#include "TileDrawer.h"
#include <vector>
#include <allegro5/allegro_primitives.h>
#include "GFuns.h"
#include "Scaler.h"
using namespace std;

void TileDrawer::mixBitmaps(ALLEGRO_BITMAP* aImg, ALLEGRO_BITMAP* aMask, ALLEGRO_BITMAP* aMask2){
	static ALLEGRO_BITMAP* mixer = al_create_bitmap(_tileSize,_tileSize);
	al_set_target_bitmap(mixer);
	al_clear_to_color(color.blank);
	al_draw_bitmap(aMask,0,0,0);
	if(aMask2) al_draw_bitmap(aMask2,0,0,0);

	al_set_target_bitmap(aImg);
	al_set_blender(ALLEGRO_DEST_MINUS_SRC,ALLEGRO_ZERO,ALLEGRO_ALPHA);
	al_draw_bitmap(mixer,0,0,0);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);	
}

void TileDrawer::drawTree(int aLower){
	/**************/
	/* ACACIA
	/**************/
	if(aLower == SAVANNA){
		if(rand()%10 > 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = s*2/5+rand()%(s/5);
			float treeNodeY = s*2/3;
			int branches = rand()%5+2;
			float m = s/4;
			float yMin = m/2;
			float yMax = treeNodeY-(treeBaseY-treeNodeY);

			// shadow
			float shadowRadius = s/5.0 + branches;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = rand()%3+3;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.tree);
			al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeDD,1);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_circle(treeNodeX,treeNodeY,trunk/2.0,color.treeDD,1);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry,xMin,xMax;
			for(int i=0; i<branches; i++){
				float proc = randNorm();
				ny = yMin + ((yMax-yMin)*(1-proc));
				xMin = m + (s/2-m)*proc;
				xMax = s-m - (s/2-m)*proc;
				nx = xMin + (xMax-xMin)*(rand()%100)/100.0;

				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.treeDD,trunk);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.tree,trunk-2);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = rand()%(int)(m/2)+m/2;
				ry = rx/(double)(rand()%2+2);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
		}

		/**************/
		/* BAOBAB
		/**************/
		else{
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = s/2+(rand()%(s/10)-s/20);
			float treeNodeY = s/3;
			float m = s/3;
			float yMin = m/2;
			float yMax = yMin*1.5;
			int branches = rand()%5+4;
			float trunk = rand()%4+s/4;

			// shadow
			float shadowRadius = s/3.0 + branches;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0,color.tree);
			al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0,color.treeDD,1);
			al_draw_filled_ellipse(treeNodeX,treeNodeY,trunk/2.0+1,trunk/4.0,color.tree);
			al_draw_ellipse(treeNodeX,treeNodeY,trunk/2.0+1,trunk/4.0,color.treeDD,1);

			//al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk);
			for(int r=treeBaseY; r>treeNodeY; r--){
				if(r%3 == 0) al_draw_line(treeBaseX-trunk/2.0+2,r,treeBaseX+trunk/2.0-2,r,color.treeD,1);
				if(r%3 == 1) al_draw_line(treeBaseX-trunk/2.0+2,r,treeBaseX+trunk/2.0-2,r,color.tree,1);
				if(r%3 == 2) al_draw_line(treeBaseX-trunk/2.0+2,r,treeBaseX+trunk/2.0-2,r,color.treeL,1);
				if(rand()%10 == 0) al_draw_filled_circle((rand()%((int)trunk))+treeBaseX-trunk/2,r,rand()%3+1,color.treeDD);
			}
			al_draw_line(treeBaseX-trunk/2,treeBaseY,treeNodeX-trunk/2,treeNodeY,color.treeDD,1);
			al_draw_line(treeBaseX+trunk/2,treeBaseY,treeNodeX+trunk/2,treeNodeY,color.treeDD,1);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry,xMin,xMax;
			for(int i=0; i<branches; i++){
				float proc = randNorm();
				ny = yMin + ((yMax-yMin)*(1-proc));
				xMin = m;
				xMax = s-m;
				nx = xMin + (xMax-xMin)*(rand()%100)/100.0;

				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.treeDD,trunk/3.0);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.tree,trunk/3.0-2);
				//al_draw_line(treeBaseX+(),treeBaseY,nx,ny,color.tree,1);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = rand()%(int)(m/2)+m/2;
				ry = rx/(double)(rand()%2+2);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
		}
	}

	/**************/
	/* CACTUS
	/**************/
	if(aLower == DESERT){
		float treeBaseX = s/2;
		float treeBaseY = s*4/5;
		float treeNodeX = s/2;
		float treeNodeY = randInterval(s/5,treeBaseY-s/3);
		int branches = randInterval(1,4);
		float m = s/8;

		// shadow
		float shadowRadius = s/5.0+branches;
		al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
		al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

		// trunk
		float trunk = randInterval(7,10);
		al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0,trunk/4.0,color.leaf);
		al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0,trunk/4.0,color.leafDD,1);
		al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.leafDD);
		al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0-1,color.leaf);
		al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.leafDD,trunk);
		al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.leaf,trunk-2);
		//a/l_draw_line

		// branches
		for(int i=0; i<branches; i++){
			float nx = treeBaseX;
			float ny = randInterval(treeBaseY-1.5*m,treeNodeY+1.5*m);

			float ex = rand()%2;
			if(ex) ex = randInterval(treeBaseX-0.5*m,treeBaseX-1.5*m);
			else ex = randInterval(treeBaseX+0.5*m,treeBaseX+1.5*m);
			float ey = randInterval(ny-m,ny-(treeBaseY-treeNodeY)/2);

			ALLEGRO_COLOR col;
			if(i<branches/3) col = color.leaf;
			else if(i<branches*2/3) col = color.leafL;
			else col = color.leafL;

			Node sp;
			sp.x = ex;
			sp.y = ny;
			float points[8] = {nx,ny,sp.x,sp.y,sp.x,sp.y,ex,ey};
			float leaf = trunk-1;
			al_draw_spline(points,color.leafDD,leaf);
			al_draw_filled_circle(ex,ey,leaf/2,color.leafDD);
			al_draw_spline(points,col,leaf-2);
			al_draw_filled_circle(ex,ey,(leaf-2)/2,col);
		}

		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int i=0; i<s; i++)
			for(int j=0; j<s; j++){
				ALLEGRO_COLOR cl = al_get_pixel(disp,i,j);
				if(eq(cl,color.leaf) || eq(cl,color.leafL) || eq(cl,color.leafD)){
					if(i%2 == 0) al_put_pixel(i,j,color.leaf);
					else if(eq(cl,color.leaf)) al_put_pixel(i,j,color.leafD);
					//if(i%4 == 2) al_put_pixel(i,j,color.leafD);
					if(rand()%10 == 0) al_put_pixel(i,j,color.leafDD);
				}

				//if(al_get_pixel(disp,i,j).r == color.mpink.r) al_put_pixel(i,j,col[rand()%3]);
			}
			al_unlock_bitmap(disp);
	}

	/**************/
	/* STEPPE OAK
	/**************/
	if(aLower == STEPPE){
		float treeBaseX = s/2;
			float treeBaseY = s*5/6;
			float treeNodeX = randInterval(s/2-s/16,s/2+s/16);
			float treeNodeY = s*5/6;
			int branches = rand()%5+10;
			float m = s/10;
			float yMin = treeNodeY-5*m;
			float yMax = treeNodeY-m;

			// shadow
			float shadowRadius = s/5.0;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = rand()%3+3;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.tree);
			al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeDD,1);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_circle(treeNodeX,treeNodeY,trunk/2.0,color.treeDD,1);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry,xMin,xMax;
			for(int i=0; i<branches; i++){
				float proc = randNorm();
				ny = yMin + ((yMax-yMin)*(1-proc));
				xMin = s/2-2*m + (s/2-m)*proc;
				xMax = s/2+2*m - (s/2-m)*proc;
				nx = xMin + (xMax-xMin)*(rand()%100)/100.0;

				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.treeDD,trunk);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.tree,trunk-2);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = randInterval(s/12,s/16);
				ry = rx*randInterval(0.7,1.0);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
	}

	/**************/
	/* BANANA
	/**************/
	if(aLower == TROPIC){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/20,s/2+s/20);
			float treeNodeY = randInterval(s/3-s/8,s/3+s/8);
			int branches = randInterval(6,10);
			float m = s/8;

			// shadow
			float shadowRadius = s/5.0;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = randInterval(4,5);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeDD);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.treeDD);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.leafDD,trunk-4);

			// branches
			vector<Node> leafs;
			float nx,ny,ex,ey;
			for(int i=0; i<branches; i++){
				nx = randInterval(treeNodeX-m/2,treeNodeX+m/2);
				ny = randInterval(treeNodeY-m,treeNodeY);

				int low = m;
				al_draw_filled_ellipse(nx,ny+low,m/4,m/2,color.banana);
				al_draw_ellipse(nx,ny+low,m/4,m/2,color.bananaDD,1);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.leafDD,4);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;

				if(nx>=treeNodeX) ex = randInterval(treeNodeX,s-2*m);
				else ex = randInterval(treeNodeX,2*m);

				ey = randInterval(treeNodeY,treeNodeY+(treeBaseY-treeNodeY)/8.0);

				ALLEGRO_COLOR col;
				if((int)i<leafs.size()/3) col = color.leafD;
				else if((int)i<leafs.size()*2/3) col = color.leaf;
				else col = color.leafL;

				Node sp;
				sp.x = (nx+ex)/2;
				sp.y = (ny-(ey-ny)/2);
				float points[8] = {nx,ny,sp.x,sp.y,sp.x,sp.y,ex,ey};
				int leaf = 4;
				al_draw_spline(points,color.leafDD,leaf);
				al_draw_filled_circle(ex,ey,leaf/2,color.leafDD);
				al_draw_spline(points,col,leaf-2);
				al_draw_filled_circle(ex,ey,(leaf-2)/2,col);
			}
		}
	}

	/**************/
	/* OAK
	/**************/
	if(aLower == FOREST){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/20,s/2+s/20);
			float treeNodeY = randInterval(s/2+s/8,s/2+s/16);
			int branches = randInterval(1,3);
			float m = s/8;

			// shadow
			float shadowRadius = s/3.0;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = randInterval(10,15);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+2,trunk/4.0+2,color.treeDD);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeD);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// shades
			int shades = randInterval(3,6);
			for(int i=0; i<shades; i++){
				int sy = randInterval(treeBaseY,treeNodeY);
				int ey = randInterval(sy,treeNodeY);

				int x = randInterval(treeBaseX-trunk/2+2,treeBaseX+trunk/2-2);

				al_draw_line(x,sy,x,ey,color.treeDD,1);
			}

			// upper size
			int ory = randInterval(treeNodeY/2.0,treeNodeY/2.0);
			int orx = ory * randInterval(1,1.5);
			// upper
			al_draw_filled_ellipse(treeNodeX,treeNodeY-ory,orx,ory,color.leafD);
			al_draw_filled_ellipse(treeNodeX,treeNodeY-ory-(ory/4),orx-(orx/4),ory-(ory/4),color.leaf);
			al_draw_filled_ellipse(treeNodeX,treeNodeY-ory-(ory/2),orx-(orx/2),ory-(ory/2),color.leafL);
			al_draw_ellipse(treeNodeX,treeNodeY-ory,orx,ory,color.leafDD,1);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry;
			for(int i=0; i<branches; i++){
				float rnd = rand()%2 ? randInterval(3.14*5/8.0,3.14) : randInterval(0,3.14*3/8.0);

				//nx = randInterval(treeNodeX-trunk/2,treeNodeX+trunk/2);
				nx = treeNodeX;
				ny = randInterval(treeBaseY-m,treeNodeY);
				int miniTrunk = trunk-randInterval(2,5);
				drawDirectLine(nx,ny,s/5,rnd,color.treeDD,miniTrunk,0);
				drawDirectLine(nx,ny,s/5,rnd,color.tree,miniTrunk-2,1);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = randInterval(0.75*m,1.25*m);
				ry = rx/randInterval(1,1.5);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
		}
	}

	/**************/
	/* PISTACHIO
	/**************/

	if(aLower == SCLEROPHYLL){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/16,s/2+s/16);
			float treeNodeY = s*3/5;
			int branches = rand()%5+10;
			float m = s/10;
			float yMin = 2*m;
			float yMax = treeNodeY;

			// shadow
			float shadowRadius = s/5.0+branches/2.0;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = rand()%3+3;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.tree);
			al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeDD,1);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_circle(treeNodeX,treeNodeY,trunk/2.0,color.treeDD,1);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry,xMin,xMax;
			for(int i=0; i<branches; i++){
				float proc = randNorm();
				ny = yMin + ((yMax-yMin)*(1-proc));
				xMin = 2*m + (s/2-m)*proc;
				xMax = s-2*m - (s/2-m)*proc;
				nx = xMin + (xMax-xMin)*(rand()%100)/100.0;

				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.treeDD,trunk);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.tree,trunk-2);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = randInterval(s/10,s/14);
				ry = rx*randInterval(0.8,1.2);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
		}
	}

	/**************/
	/* PINE
	/**************/

	if(aLower == TAIGA){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/30,s/2+s/30);
			float treeNodeY = randInterval(s/2+s/6,s/2+s/12);
			float round = randInterval(s/3,s/6);

			// shadow
			float shadowRadius = round;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = randInterval(4,8);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+2,trunk/4.0+2,color.treeDD);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeD);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// layers
			int layers = randInterval(3,6);
			float step = randInterval(s/10,s/12);
			float shrink = randInterval(3,4);
			float height = randInterval(2,4);
			float ry = randInterval(3,6);
			int x1,x2,x3,y1,y2,y3;
			for(int i=0; i<layers; i++){
				x1 = treeBaseX-round+shrink*i;
				x2 = treeBaseX+round-shrink*i;
				if(x2<=x1+2){
					break;
				}
				x3 = (x1+x2)/2.0;
				y1 = y2 = treeNodeY-step*i;
				y3 = y1-step*height;

				al_draw_filled_ellipse((x1+x2)/2,y1,(x2-x1)/2,ry,color.mpink);
				al_draw_ellipse((x1+x2)/2,y1,(x2-x1)/2,ry,color.leafDD,1);
				al_draw_filled_triangle(x1,y1,x2,y2,x3,y3,color.mpink);
				al_draw_line(x1,y1,x3,y3,color.leafDD,1);
				al_draw_line(x2,y2,x3,y3,color.leafDD,1);
			}

			ALLEGRO_COLOR col[3] = {color.leaf,color.leafD,color.leafDD};
			ALLEGRO_BITMAP* disp = al_get_target_bitmap();
			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
			for(int i=0; i<s; i++)
				for(int j=0; j<s; j++){
					if(al_get_pixel(disp,i,j).r == color.mpink.r) al_put_pixel(i,j,col[rand()%3]);
				}
				al_unlock_bitmap(disp);
		}
	}

	/**************/
	/* BIRCH
	/**************/

	if(aLower == TUNDRA){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/16,s/2+s/16);
			float treeNodeY = s*4/6;
			int branches = rand()%5+5;
			float m = s/10;
			float yMin = treeNodeY-5*m;
			float yMax = treeNodeY-m;

			// shadow
			float shadowRadius = s/5.0;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = rand()%3+3;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.snow);
			al_draw_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeDD,1);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.snow);
			al_draw_circle(treeNodeX,treeNodeY,trunk/2.0,color.treeDD,1);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.snow,trunk-2);

			for(int i=0; i<s/6; i++)
				al_draw_filled_circle(randInterval(treeBaseX-trunk/2,treeBaseX+trunk/2),randInterval(treeBaseY,treeNodeY),
				1,color.treeDD);

			// branches
			vector<Node> leafs;
			float nx,ny,rx,ry,xMin,xMax;
			for(int i=0; i<branches; i++){
				float proc = randNorm();
				ny = yMin + ((yMax-yMin)*(1-proc));
				xMin = s/2-2*m + (s/2-m)*proc;
				xMax = s/2+2*m - (s/2-m)*proc;
				nx = xMin + (xMax-xMin)*(rand()%100)/100.0;

				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.treeDD,trunk);
				al_draw_line(treeNodeX,treeNodeY,nx,ny,color.snow,trunk-2);

				Node l = {nx,ny};
				leafs.push_back(l);
			}

			// leafs
			for(unsigned int i=0; i<leafs.size(); i++){
				nx = leafs[i].x;
				ny = leafs[i].y;
				rx = randInterval(s/10,s/14);
				ry = rx*randInterval(1.1,1.3);
				al_draw_filled_ellipse(nx,ny,rx,ry,color.leafD);
				al_draw_filled_ellipse(nx,ny-(ry/4),rx-(rx/4),ry-(ry/4),color.leaf);
				al_draw_filled_ellipse(nx,ny-(ry/2),rx-(rx/2),ry-(ry/2),color.leafL);
				al_draw_ellipse(nx,ny,rx,ry,color.leafDD,1);
			}
		}
	}

	/**************/
	/* SNOW PINE
	/**************/

	if(aLower == POLAR){
		if(rand()%10 >= 0){
			float treeBaseX = s/2;
			float treeBaseY = s*4/5;
			float treeNodeX = randInterval(s/2-s/30,s/2+s/30);
			float treeNodeY = randInterval(s/2+s/6,s/2+s/10);
			float round = randInterval(s/5,s/7);

			// shadow
			float shadowRadius = round;
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius,shadowRadius/3.0,color.shadowLL);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,shadowRadius/2.0,shadowRadius/6.0,color.shadowLL);

			// trunk
			float trunk = randInterval(2,5);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+2,trunk/4.0+2,color.treeDD);
			al_draw_filled_ellipse(treeBaseX,treeBaseY,trunk/2.0+1,trunk/4.0+1,color.treeD);
			al_draw_filled_circle(treeNodeX,treeNodeY,trunk/2.0,color.tree);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.treeDD,trunk);
			al_draw_line(treeBaseX,treeBaseY,treeNodeX,treeNodeY,color.tree,trunk-2);

			// layers
			int layers = randInterval(3,6);
			float step = randInterval(s/12,s/14);
			float shrink = randInterval(3,4);
			float height = randInterval(1,3);
			float ry = randInterval(3,6);
			int x1,x2,x3,y1,y2,y3;
			for(int i=0; i<layers; i++){
				x1 = treeBaseX-round+shrink*i;
				x2 = treeBaseX+round-shrink*i;
				if(x2<=x1+2) break;
				x3 = (x1+x2)/2.0;
				y1 = y2 = treeNodeY-step*i;
				y3 = y1-step*height;

				al_draw_filled_ellipse((x1+x2)/2,y1,(x2-x1)/2,ry,color.mpink);
				al_draw_ellipse((x1+x2)/2,y1,(x2-x1)/2,ry,color.snowDD,1);
				al_draw_filled_triangle(x1,y1,x2,y2,x3,y3,color.mpink);
				al_draw_line(x1,y1,x3,y3,color.snowDD,1);
				al_draw_line(x2,y2,x3,y3,color.snowDD,1);
			}

			ALLEGRO_COLOR col[3] = {color.snow,color.snowD,color.snowL};
			ALLEGRO_BITMAP* disp = al_get_target_bitmap();
			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
			for(int i=0; i<s; i++)
				for(int j=0; j<s; j++){
					if(al_get_pixel(disp,i,j).r == color.mpink.r) al_put_pixel(i,j,col[rand()%3]);
				}
				al_unlock_bitmap(disp);
		}
	}
}

void TileDrawer::drawBiome(int aLower){
	int s = _tileSize;

	if(aLower == OCEAN){
		al_draw_filled_rectangle(0,0,s,s,color.water);
		double amp = s/2;
		int freq = 32;

		double phase = (666)%freq * 6.28/(double)freq; // !!!
		double add = sin((0)/50.0+phase)*amp/2+amp;
		double thik = sin((0)/50.0+phase-1.57)*5.0+10;

		float points[8] = {0,0,add,0,s-add,s,s,s};
		al_draw_spline(points,color.waterL,thik);
		al_draw_filled_circle(0,0,thik/2.0,color.waterL);

		for(int c=0; c<thik/5; c++) al_draw_filled_circle(rand()%s+thik,rand()%s+thik,((rand()%30)/10.0),color.waterLL);
	}

	if(aLower == COAST){
		al_draw_filled_rectangle(0,0,s,s,color.sand);
		double thik = 10;
		float points[8] = {0,0,s/2.0,0,s/2.0,s,s,s};
		al_draw_spline(points,color.sandD,thik);
		al_draw_filled_circle(0,0,thik/2.0,color.sandD);
		al_draw_filled_circle(s,s,thik/2.0,color.sandD);
		int dirts = rand()%31+20;
		for(int c=0; c<dirts; c++)	al_draw_filled_circle(rand()%s,rand()%s,rand()%3+1,color.sandD);
	}

	else if(aLower == LAKE){
		al_draw_filled_rectangle(0,0,s,s,color.waterL);
	}

	else if(aLower == SAVANNA){
		al_draw_filled_rectangle(0,0,s,s,color.sandD);
		int grass = rand()%21+20;
		for(int c=0; c<grass; c++) al_draw_filled_circle(rand()%s,rand()%s,rand()%2+1,color.grass);
		int dark = rand()%11+10;
		for(int c=0; c<dark; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.sand);
		int light = rand()%4+4;
		for(int c=0; c<light; c++) al_draw_filled_circle(rand()%s,rand()%s,2,color.sand);
	}

	else if(aLower == DESERT){
		al_draw_filled_rectangle(0,0,s,s,color.sandD);
		int dark = rand()%6+5;
		for(int c=0; c<dark; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.sand);
		int light = rand()%2+2;
		for(int c=0; c<light; c++) al_draw_filled_circle(rand()%s,rand()%s,2,color.sand);
	}

	else if(aLower == STEPPE){
		al_draw_filled_rectangle(0,0,s,s,color.sandD);
		int dark = rand()%6+5;
		for(int c=0; c<dark; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.sand);
	}

	else if(aLower == TROPIC){
		al_draw_filled_rectangle(0,0,s,s,color.grass);
		int sand = rand()%11+10;
		for(int c=0; c<sand; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.sand);
		int dark = rand()%11+10;
		for(int c=0; c<dark; c++)	al_draw_filled_circle(rand()%s,rand()%s,1,color.grassD);
		int light = rand()%4+4;
		for(int c=0; c<light; c++) al_draw_filled_circle(rand()%s,rand()%s,rand()%2 ? 2 : 3,color.grassL);
	}

	else if(aLower == FOREST){
		al_draw_filled_rectangle(0,0,s,s,color.grass);
		int dark = rand()%21+20;
		for(int c=0; c<dark; c++)	al_draw_filled_circle(rand()%s,rand()%s,1,color.grassD);
		int light = rand()%8+8;
		for(int c=0; c<light; c++) al_draw_filled_circle(rand()%s,rand()%s,rand()%5+1,color.grassL);
	}

	else if(aLower == SCLEROPHYLL){
		al_draw_filled_rectangle(0,0,s,s,color.grass);
		int dark = rand()%11+10;
		for(int c=0; c<dark; c++)	al_draw_filled_circle(rand()%s,rand()%s,1,color.grassD);
		int light = rand()%4+4;
		for(int c=0; c<light; c++) al_draw_filled_circle(rand()%s,rand()%s,rand()%5+1,color.grassL);
	}
	
	else if(aLower == TAIGA){
		al_draw_filled_rectangle(0,0,s,s,color.taiga);
		int grass = rand()%11+10;
		for(int c=0; c<grass; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.tundra);
		int grassD = rand()%21+20;
		for(int c=0; c<grassD; c++) al_draw_filled_circle(rand()%s,rand()%s,1.5,color.grass);
	}

	else if(aLower == TUNDRA){
		al_draw_filled_rectangle(0,0,s,s,color.tundra);
		int grass = rand()%11+10;
		for(int c=0; c<grass; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.tundraD);
		int dark = rand()%11+10;
		for(int c=0; c<dark; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.taiga);
	}

	else if(aLower == POLAR){
		al_draw_filled_rectangle(0,0,s,s,color.snow);
		int dark = rand()%4+4;
		for(int c=0; c<dark; c++) al_draw_filled_circle(rand()%s,rand()%s,1,color.snowL);
	}
}

void TileDrawer::drawRoadEdge(int aX1, int aY1, int aX2, int aY2, int aDir){
	int start = 0;
	int end = 0;
	int j = 0;
	int mult = 0;

	if(aDir == 0 || aDir == 1){
		start = aY1 < aY2 ? aY1 : aY2;
		end = aY1 > aY2 ? aY1 : aY2;
		j = aX1;
	}
	else{
		start = aX1 < aX2 ? aX1 : aX2;
		end = aX1 > aX2 ? aX1 : aX2;
		j = aY1;
	}
	mult = (aDir == 1 || aDir == 3) ? 1 : -1;

	ALLEGRO_COLOR cl[8] = {color.shadowLL,color.shadowLL,color.shadowL,color.roadDD,color.roadD,color.roadD,color.road,color.road};
	if(aDir == 2 || aDir == 3){
		for(int x=start; x<end; x++){
			int rnd = rand()%2;
			int rnd2 = rand()%2;
			al_put_blended_pixel(x,rnd+j-2*mult,cl[0]);
			al_put_blended_pixel(x,rnd+j-1*mult,cl[1]);
			al_put_blended_pixel(x,rnd+j,cl[2]);
			al_put_pixel(x,rnd+j+1*mult,cl[3]);
			al_put_pixel(x,rnd+j+2*mult,cl[4]);
			al_put_pixel(x,rnd+j+3*mult,cl[5]);
			al_put_pixel(x,rnd+j+4*mult,cl[6]);
			al_put_pixel(x,rnd+j+5*mult,cl[7]);
		}
	}
	else{
		for(int x=start; x<end; x++){
			int rnd = rand()%2;
			int rnd2 = rand()%2;
			al_put_blended_pixel(rnd+j-2*mult,x,cl[0]);
			al_put_blended_pixel(rnd+j-1*mult,x,cl[1]);
			al_put_blended_pixel(rnd+j,x,cl[2]);
			al_put_pixel(rnd+j+1*mult,x,cl[3]);
			al_put_pixel(rnd+j+2*mult,x,cl[4]);
			al_put_pixel(rnd+j+3*mult,x,cl[5]);
			al_put_pixel(rnd+j+4*mult,x,cl[6]);
			al_put_pixel(rnd+j+5*mult,x,cl[7]);
		}
	}
}

void TileDrawer::drawRoad(bool aConnections[4], int aRoadSize){
	ALLEGRO_BITMAP* dispOrg = al_get_target_bitmap();
  static ALLEGRO_BITMAP* buffer = al_create_bitmap(_tileSize,_tileSize);
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	static int s = _tileSize;
	static double roadSize = aRoadSize/2;
	if(roadSize == 0) roadSize = s/3;
	static double del = s/2-roadSize/2;

	// point map of the road tile
	static double road[17][2] = {
		{del,0},{s-del-1,0},{0,del},{del,del},
		{s-1-del,del},{s,del},{0,s-1-del},{del,s-1-del},
		{s-1-del,s-1-del},{s,s-1-del},{del,s},{s-1-del,s},
		{s/2.0,del},{del,s/2.0},{s-1-del,s/2.0},{s/2.0,s-1-del},{s/2.0,s/2.0},
	};

	// circle in the middle
	ALLEGRO_COLOR cl[8] = {color.shadowLL,color.blank,color.blank,color.roadDD,color.roadD,color.roadD,color.road,color.road};
	for(int i=1; i>-7; i--) al_draw_filled_circle(road[16][0],road[16][1],roadSize/2+i,cl[1-i]);

	// check directions
	/*bool dirs[4] = {0};
	for(int d=0; d<4; d++){
		int tr = _Map->getUpper(aX+dir[d][0],aY+dir[d][1]);
		if(tr == CITY || tr == ROAD || tr == BRIDGE || tr == PORT) dirs[d] = true;
	}*/

	// pixel params tab
	static int t[4][24] = {
		{2,15,2,2,3,3,3,6,6,7,3,2,2,3,3,12,12,3,3,7,7,15,15,2},
		{12,9,4,4,5,5,3,8,8,9,9,2,2,12,12,4,4,3,3,15,15,8,8,2},
		{0,14,0,0,3,3,1,1,1,4,4,0,0,3,3,13,13,1,1,4,4,14,14,0},
		{13,11,7,7,10,10,1,8,8,11,11,0,0,13,13,7,7,1,1,14,14,8,8,0}
	};

	// drawing nodes in different directions
	for(int i=0; i<4; i++){
		if(aConnections[i]){
			float x1 = road[t[i][0]][0];
			float y1 = road[t[i][0]][1];
			float x2 = road[t[i][1]][0];
			float y2 = road[t[i][1]][1];
			if(i == 0 || i == 1) y1++;
			else x1++;
			al_draw_filled_rectangle(x1,y1,x2,y2,color.road);
			for(int p=0; p<10; p++) al_draw_filled_circle(randInterval(x1,x2),randInterval(y1,y2),rand()%2+1,color.roadD);
			for(int p=0; p<5; p++) al_draw_filled_circle(randInterval(x1,x2),randInterval(y1,y2),1,color.roadDD);

			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_WRITEONLY);
			drawRoadEdge(road[t[i][2]][0],road[t[i][3]][1],road[t[i][4]][0],road[t[i][5]][1],t[i][6]);
			drawRoadEdge(road[t[i][7]][0],road[t[i][8]][1],road[t[i][9]][0],road[t[i][10]][1],t[i][11]);
			if(!aConnections[t[i][12]]) drawRoadEdge(road[t[i][13]][0],road[t[i][14]][1],road[t[i][15]][0],road[t[i][16]][1],t[i][17]);
			if(!aConnections[t[i][18]]) drawRoadEdge(road[t[i][19]][0],road[t[i][20]][1],road[t[i][21]][0],road[t[i][22]][1],t[i][23]);
			al_unlock_bitmap(disp);
		}
	}

	al_set_target_bitmap(dispOrg);
	unsigned char alpha = 200;
	al_draw_tinted_bitmap(buffer,al_map_rgba(255+alpha,255+alpha,255+alpha,alpha),0,0,0);
}

//*********************************************
//* WORLD MAP SPECIFIC
//*********************************************

void TileDrawer::drawRiverCoast(int aX1, int aY1, int aX2, int aY2, int aDir){
	int start = 0;
	int end = 0;
	int j = 0;
	int mult = 0;

	if(aDir == 0 || aDir == 1){
		start = aY1 < aY2 ? aY1 : aY2;
		end = aY1 > aY2 ? aY1 : aY2;
		j = aX1;
	}
	else{
		start = aX1 < aX2 ? aX1 : aX2;
		end = aX1 > aX2 ? aX1 : aX2;
		j = aY1;
	}
	mult = (aDir == 1 || aDir == 3) ? 1 : -1;

	if(aDir == 2 || aDir == 3){
		for(int x=start; x<end; x++){
			int rnd = rand()%2;
			int rnd2 = rand()%2;
			al_put_blended_pixel(x,rnd+j-2*mult,color.shadowL);
			al_put_blended_pixel(x,rnd+j-1*mult,color.shadow);
			al_put_pixel(x,rnd+j,color.groundL);
			al_put_pixel(x,rnd+j+1*mult,color.groundL);
			al_put_pixel(x,rnd+j+2*mult,color.groundD);
			al_put_pixel(x,rnd+j+3*mult,color.water);
			al_put_pixel(x,rnd+j+4*mult,color.water);
			al_put_pixel(x,rnd+j+5*mult,color.waterD);
		}
	}
	else{
		for(int x=start; x<end; x++){
			int rnd = rand()%2;
			int rnd2 = rand()%2;
			al_put_blended_pixel(rnd+j-2*mult,x,color.shadowL);
			al_put_blended_pixel(rnd+j-1*mult,x,color.shadow);
			al_put_pixel(rnd+j,x,color.groundL);
			al_put_pixel(rnd+j+1*mult,x,color.groundL);
			al_put_pixel(rnd+j+2*mult,x,color.groundD);
			al_put_pixel(rnd+j+3*mult,x,color.water);
			al_put_pixel(rnd+j+4*mult,x,color.water);
			al_put_pixel(rnd+j+5*mult,x,color.waterD);
		}
	}
}

void TileDrawer::drawRiver(bool aConnections[4], bool aConfl){
	int s = _tileSize;
	static double riverSize = s/2;
	static double del = s/2-riverSize/2;

	// point map of the river tile
	static double river[17][2] = {
		{del,0},{s-del-1,0},{0,del},{del,del},
		{s-1-del,del},{s,del},{0,s-1-del},{del,s-1-del},
		{s-1-del,s-1-del},{s,s-1-del},{del,s},{s-1-del,s},
		{s/2.0,del},{del,s/2.0},{s-1-del,s/2.0},{s/2.0,s-1-del},{s/2.0,s/2.0},
	};

	// circle in the middle
	ALLEGRO_COLOR cl[8] = {color.shadow,color.groundL,color.groundL,color.groundD,color.water,color.water,color.waterD,color.waterL};
	for(int i=1; i>-7; i--) al_draw_filled_circle(river[16][0],river[16][1],riverSize/2+i,cl[1-i]);

	// check directions
	//bool dirs[4] = {0};
	// case with only confluence generated
	if(aConfl){
		aConnections[0] = aConnections[1] = false;
		aConnections[2] = aConnections[3] = true;
	}
	// normal case
	/*else{
		for(int d=0; d<4; d++){
			int tr = _Map->getUpper(aX+dir[d][0],aY+dir[d][1]);
			if(tr == TNONE || tr == RIVER || tr == BRIDGE || tr == CONFLUENCE) dirs[d] = true;
		}
	}*/

	// pixel params tab
	static int t[4][24] = {
		{2,15,2,2,3,3,3,6,6,7,3,2,2,3,3,12,12,3,3,7,7,15,15,2},
		{12,9,4,4,5,5,3,8,8,9,9,2,2,12,12,4,4,3,3,15,15,8,8,2},
		{0,14,0,0,3,3,1,1,1,4,4,0,0,3,3,13,13,1,1,4,4,14,14,0},
		{13,11,7,7,10,10,1,8,8,11,11,0,0,13,13,7,7,1,1,14,14,8,8,0}
	};

	// drawing nodes in different directions
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	for(int i=0; i<4; i++){
		if(aConnections[i]){
			al_draw_filled_rectangle(river[t[i][0]][0],river[t[i][0]][1],river[t[i][1]][0],river[t[i][1]][1],color.waterL);
			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_WRITEONLY);
			drawRiverCoast(river[t[i][2]][0],river[t[i][3]][1],river[t[i][4]][0],river[t[i][5]][1],t[i][6]);
			drawRiverCoast(river[t[i][7]][0],river[t[i][8]][1],river[t[i][9]][0],river[t[i][10]][1],t[i][11]);
			if(!aConnections[t[i][12]]) drawRiverCoast(river[t[i][13]][0],river[t[i][14]][1],river[t[i][15]][0],river[t[i][16]][1],t[i][17]);
			if(!aConnections[t[i][18]]) drawRiverCoast(river[t[i][19]][0],river[t[i][20]][1],river[t[i][21]][0],river[t[i][22]][1],t[i][23]);
			al_unlock_bitmap(disp);
		}
	}
}

void TileDrawer::drawBridge(bool aV){
	bool horz[4] = {1,1,0,0};
	bool vert[4] = {0,0,1,1};
	if(aV){
		drawRoad(vert);
		drawRiver(horz);
	}
	else{
		drawRoad(horz);
		drawRiver(vert);
	}

	int s = _tileSize;
	double left = s/(rand()%5+8);
	double top = s/(rand()%2+3.5);
	double m = s/(rand()%11+20);
	double b = s/(rand()%5+8);
	double w = rand()%((int)((s-2*left)/4))+left*1.3;

	if(!aV){
		// shadow
		al_draw_line(left-1,top,left-1,s-top+b/2,color.shadow,1);
		al_draw_line(left-2,top+b/2,left-2,s-top,color.shadowL,1);
		al_draw_line(left-3,top+b,left-3,s-top-b/2,color.shadowLL,1);
		al_draw_line(s-left+1,top,s-left+1,s-top+b/2,color.shadow,1);
		al_draw_line(s-left+2,top+b/2,s-left+2,s-top,color.shadowL,1);
		al_draw_line(s-left+3,top+b,s-left+3,s-top-b/2,color.shadowLL,1);

		// floor
		al_draw_filled_rectangle(left,top,s-left,s-top+b/2,color.bridge);
		al_draw_rectangle(left,top,s-left,s-top+b/2,color.bridgeD,1);
		for(int i=left+3; i<s-left-2; i++){
			if(i%8 == 0) al_draw_line(i,top+m,i,s-top-m,color.bridgeL,1);
			else if(i%8 == 1) al_draw_line(i,top+m,i,s-top-m,color.bridgeL,1);
			else if(i%8 == 2) al_draw_line(i,top+m,i,s-top-m,color.bridgeLL,1);
			else if(i%8 == 3) al_draw_line(i,top+m,i,s-top-m,color.bridgeL,1);
			else if(i%8 == 6) al_draw_line(i,top+m,i,s-top-m,color.bridgeL,1);
		}

		// barrier
		for(int c=0; c<2; c++){
			al_draw_filled_rectangle(w,top-b-m,w+m,top-b,color.metalDD);
			al_draw_filled_rectangle(s-w,top-b-m,s-w-m,top-b,color.metalDD);
			al_draw_filled_rectangle(left,top-b,s-left,top-b+m,color.metal);
			al_draw_filled_rectangle(left,top-m,s-left,top,color.metal);
			for(int i=left; i<s-left-m; i+=2*m){
				al_draw_filled_rectangle(i,top-b,i+m,top,color.metalD);
				al_draw_rectangle(i+m,top-b+m,i+2*m,top-m,color.metalDD,0); 
			}
			al_draw_rectangle(left,top-b,s-left,top,color.metalDD,1);
			top = s-top;
		}
	}
	else{
		int t = left;
		int left = top;
		int top = t;

		// shadow
		al_draw_line(left,top-1,s-left,top-1,color.shadow,1);
		al_draw_line(left+b/2,top-2,s-left-b/2,top-2,color.shadowL,1);
		al_draw_line(left+b,top-3,s-left-b,top-3,color.shadowLL,1);
		al_draw_line(left,s-top+1,s-left,s-top+1,color.shadow,1);
		al_draw_line(left+b/2,s-top+2,s-left-b/2,s-top+2,color.shadowL,1);
		al_draw_line(left+b,s-top+3,s-left-b,s-top+3,color.shadowLL,1);

		// floor
		al_draw_filled_rectangle(left,top,s-left,s-top,color.bridge);
		al_draw_rectangle(left,top,s-left,s-top,color.bridgeD,1);
		for(int i=top+3; i<s-top-2; i++){
			if(i%8 == 0) al_draw_line(left+m,i,s-left-m,i,color.bridgeL,1);
			else if(i%8 == 1) al_draw_line(left+m,i,s-left-m,i,color.bridgeL,1);
			else if(i%8 == 2) al_draw_line(left+m,i,s-left-m,i,color.bridgeLL,1);
			else if(i%8 == 3) al_draw_line(left+m,i,s-left-m,i,color.bridgeL,1);
			else if(i%8 == 6) al_draw_line(left+m,i,s-left-m,i,color.bridgeL,1);
		}

		// barrier
		for(int c=0; c<2; c++){
			al_draw_filled_rectangle(left,top,left-m,s-top,color.metal);
			al_draw_rectangle(left,top,left-m,s-top,color.metalDD,1);
			al_draw_filled_rectangle(left-m,w,left,w+m,color.metalDD);
			al_draw_filled_rectangle(left-m,s-w,left,s-w+m,color.metalDD);
			left = s-left+m;
		}
	}
}

void TileDrawer::drawConfluence(int aDir){
	int s = _tileSize;
	static ALLEGRO_BITMAP* confl = al_create_bitmap(s,s);
	static bool initConfl;
	if(!initConfl){
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		ALLEGRO_BITMAP* mask = al_create_bitmap(s,s);
		al_set_target_bitmap(mask);
		drawGradient(0,0,s,s/2,color.black,color.blank);
		al_set_target_bitmap(confl);
		bool tempCon[4] = {0,0,0,0};
		drawRiver(tempCon,1);
		mixBitmaps(confl,mask,NULL);
		al_destroy_bitmap(mask);
		al_set_target_bitmap(disp);
	}
	float rot = 0;
	if(aDir == RIGHT) rot = ALLEGRO_PI*0.5;
	else if(aDir == LEFT) rot = ALLEGRO_PI*1.5;
	else if(aDir == DOWN) rot = -ALLEGRO_PI;
	al_draw_rotated_bitmap(confl,s/2.0,s/2.0,s/2.0,s/2.0,rot,0);
}

void TileDrawer::drawMountain(int aLower){
	int s = _tileSize;

	// defining color of the mountain
	ALLEGRO_COLOR cl = color.mountain;
	ALLEGRO_COLOR clB = color.mountainDD;
	int rockColor = TROPIC;
	if(aLower == SAVANNA || aLower == STEPPE || aLower == DESERT){
		cl = color.mountainGold;
		clB = color.mountainGoldDD;
		rockColor = SAVANNA;
	}
	if(aLower == TUNDRA || aLower == POLAR){
		cl = color.mountain;
		clB = color.mountainDD;
		rockColor = TUNDRA;
	}

	// definig inverse heigth of the mountain based on the elevation
	float hi = 1;
	if(aLower == DESERT || aLower == FOREST || aLower == TUNDRA) hi = 0.5;
	else if(aLower == STEPPE || aLower == SCLEROPHYLL || aLower == POLAR) hi = 0;

	// random calculation of mountain coordinates
	float leftX = randInterval(s/6,s/4);
	float rightX = s-randInterval(s/6,s/4);
	float base = s-s/6;
	float top = s/2-randInterval(s/8,s/4);
	top += hi*s/10.0;

	float peak = randInterval(top+s/8,top+s/4);

	leftX += hi*s/10;
	rightX -= hi*s/10;

	float minStep = (rightX-leftX)/8;
	float maxStep = (rightX-leftX)/3;

	// shadow
	float shadowRadius = (rightX-leftX)/2;
	al_draw_filled_ellipse((rightX+leftX)/2,base,shadowRadius,shadowRadius/3.0,color.shadowLL);
	al_draw_filled_ellipse((rightX+leftX)/2,base,shadowRadius+shadowRadius/5.0,shadowRadius/3.0+shadowRadius/5.0,color.shadowLL);

	// mountain base
	float x = leftX;
	float y = base;
	float x2 = 0;
	float y2 = 0;
	while(x != rightX){
		x2 = x + randInterval(minStep,maxStep);

		if(x2 >= rightX-minStep){
			x2 = rightX;
			y2 = base;
		}
		else y2 = randInterval(top,peak);

		al_draw_filled_triangle(x,base,x2,base,x,y,cl);
		al_draw_filled_triangle(x2,base,x,y,x2,y2,cl);
		al_draw_line(x,y,x2,y2,clB,1);

		x = x2;
		y = y2;
	}
	
	// colorizing
	vector<ALLEGRO_COLOR> col;
	if(rockColor == SAVANNA){
		col.push_back(color.mountainGoldDD);
		col.push_back(color.mountainGoldD);
		col.push_back(color.mountainGold);
		col.push_back(color.mountainGoldL);
		col.push_back(color.mountainGoldLL);
		col.push_back(color.mountainGoldLL);
	}
	else if(rockColor == TUNDRA){
		col.push_back(color.mountainDD);
		col.push_back(color.mountainD);
		col.push_back(color.snowDD);
		col.push_back(color.snowD);
		col.push_back(color.snow);
		col.push_back(color.snowL);
	}
	else{
		col.push_back(color.mountainDD);
		col.push_back(color.mountainD);
		col.push_back(color.mountain);
		col.push_back(color.mountainL);
		col.push_back(color.mountainLL);
		col.push_back(color.mountainLL);
	}
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
	Scaler sc(leftX, rightX, 0, ALLEGRO_PI);
	for(int i=0; i<s; i++)
		for(int j=0; j<s; j++){
			if(eq(al_get_pixel(disp,i,j),cl)){

				float fj = j-10*sin(sc.scale(i))+10;

				int r = 4;
				if(fj>base-(base-peak)/4) r = 1;
				else if(fj>base-(base-peak)*2/4) r = 2;
				else if(fj>base-(base-peak)*3/4) r = 3;

				if(rand()%10 == 0) r++;
				else if(rand()%10 == 0) r--;

				al_put_pixel(i,j,col[r]);
			}
		}
		al_unlock_bitmap(disp);

}

void TileDrawer::drawPort(bool aConnections[4]){
	int s = _tileSize;
	int floorW = s/3;

	if(aConnections[0] || aConnections[1]){
		// poles
		int poles = 6;
		int dist = s/poles+1;
		int poleY = s*3/4;
		for(int i=0; i<poles; i++){
			al_draw_circle(dist*i+3, poleY-1,3,color.waterLL,1);
			al_draw_line(dist*i+3,s/2,dist*i+3,poleY,color.bridgeD,4);
		}

		// floor
		al_draw_filled_rectangle(0,s/2-floorW/2,s,s/2+floorW/2,color.bridge);
		al_draw_rectangle(0,s/2-floorW/2,s,s/2+floorW/2,color.bridgeD,1);
		for(int i=3; i<s-2; i++){
			if(i%8 == 0) al_draw_line(i,s/2-floorW/2,i,s/2+floorW/2-1,color.bridgeL,1);
			else if(i%8 == 1) al_draw_line(i,s/2-floorW/2,i,s/2+floorW/2-1,color.bridgeL,1);
			else if(i%8 == 2) al_draw_line(i,s/2-floorW/2,i,s/2+floorW/2-1,color.bridgeLL,1);
			else if(i%8 == 3) al_draw_line(i,s/2-floorW/2,i,s/2+floorW/2-1,color.bridgeL,1);
			else if(i%8 == 5) al_draw_line(i,s/2-floorW/2,i,s/2+floorW/2-1,color.bridgeL,1);
		}
	}
	if(aConnections[2] || aConnections[3]){
		floorW*=1.5;

		// poles
		al_draw_circle(s/2-floorW/2+3, s*5/6-1,3,color.waterLL,1);
		al_draw_line(s/2-floorW/2+3,s/2,s/2-floorW/2+3,s*5/6,color.bridgeD,4);
		al_draw_circle(s/2+floorW/2-3, s*5/6-1,3,color.waterLL,1);
		al_draw_line(s/2+floorW/2-3,s/2,s/2+floorW/2-3,s*5/6,color.bridgeD,4);

		// floor
		int floorEnd = s*3/4;
		if(aConnections[3]){
			floorEnd = s-2;
			al_draw_line(s/2-floorW/2,floorEnd+1,s/2+floorW/2,floorEnd+1,color.shadow,1);
			al_draw_line(s/2-floorW/2,floorEnd+2,s/2+floorW/2,floorEnd+2,color.shadowL,1);
		}

		al_draw_filled_rectangle(s/2-floorW/2,0,s/2+floorW/2,floorEnd,color.bridge);
		al_draw_rectangle(s/2-floorW/2,0,s/2+floorW/2,floorEnd,color.bridgeD,1);
		for(int i=3; i<floorEnd-2; i++){
			if(i%8 == 0) al_draw_line(s/2-floorW/2,i,s/2+floorW/2-1,i,color.bridgeL,1);
			else if(i%8 == 1) al_draw_line(s/2-floorW/2,i,s/2+floorW/2-1,i,color.bridgeL,1);
			else if(i%8 == 2) al_draw_line(s/2-floorW/2,i,s/2+floorW/2-1,i,color.bridgeLL,1);
			else if(i%8 == 3) al_draw_line(s/2-floorW/2,i,s/2+floorW/2-1,i,color.bridgeL,1);
			else if(i%8 == 5) al_draw_line(s/2-floorW/2,i,s/2+floorW/2-1,i,color.bridgeL,1);
		}
	}

	// house
	int w = s/2;
	int h = s*2/3;
	int dX = 0;
	if(aConnections[1]) dX = s - w;
	else if(aConnections[0]) dX = 0;
	if(aConnections[2] || aConnections[3]) dX = s/2-w/2;
	int dY = s/2+floorW/2 - h;
	int eX = dX+w;
	int eY = dY+h;

	Node base1 = {dX+randInterval(w/7,w/4), dY+h/2+randInterval(h/6,h/4)};
	Node base2 = {eX-(base1.x-dX), eY-h/8};
	Node top = {(base1.x+base2.x)/2, base1.y - randInterval(h/6,h/4)};
	Node roof = {top.x,top.y-randInterval(h/3,h/2)};
	Node side = {base1.x-randInterval(w/8,w/10),base1.y+randInterval(w/8,w/10)};

	// shadow
	al_draw_filled_rectangle(base1.x-3,base1.y-3,base2.x+2,base2.y+2,color.shadowLL);
	al_draw_filled_rectangle(base1.x-2,base1.y-2,base2.x+1,base2.y+1,color.shadowLL);

	// stone background
	al_draw_filled_triangle(base1.x,base1.y,top.x,top.y,base2.x,base1.y,color.stoneL);
	al_draw_filled_rectangle(base1.x,base1.y,base2.x,base2.y,color.stoneL);
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
	for(int x=base1.x; x<=base2.x; x++)
		for(int y=top.y; y<=base2.y; y++){
			if(y%3 == 0 && (rand()%10) > 2) al_put_pixel(x,y,color.stone);
		}
		al_unlock_bitmap(disp);

		// front shading
		ALLEGRO_COLOR cl[3] = {color.houseB,color.stoneD,color.stone};
		for(int i=0; i<3; i++){
			al_draw_line(base1.x+i,base2.y-i,base1.x+i,base1.y,cl[i],1);
			al_draw_line(base1.x+i,base1.y,top.x,top.y+i,cl[i],1);
			al_draw_line(top.x,top.y+i,base2.x-i,base1.y,cl[i],1);
			al_draw_line(base2.x-i,base1.y,base2.x-i,base2.y-i,cl[i],1);
			al_draw_line(base2.x-i,base2.y-i,base1.x+i,base2.y-i,cl[i],1);
		}

		// The Doors
		int doorsW = randInterval(w/6,w/5.5);
		int doorsH = randInterval(h/6,h/5.5);
		al_draw_rectangle(top.x-doorsW/2,base2.y-doorsH,top.x+doorsW/2,base2.y,color.houseB,1);
		al_draw_rectangle(top.x-doorsW/2+1,base2.y-doorsH+1,top.x+doorsW/2-1,base2.y-1,color.doorsD,1);
		al_draw_rectangle(top.x-doorsW/2+2,base2.y-doorsH+2,top.x+doorsW/2-2,base2.y-2,color.doors,1);

		// planks
		float plankX = randInterval(w/6,w/8);
		al_draw_line(base1.x+plankX,top.y,base1.x+plankX,base2.y-1,color.doorsD,1);
		al_draw_line(base2.x-plankX,top.y,base2.x-plankX,base2.y-1,color.doorsD,1);

		// roof
		for(int y=0; y<(top.y-roof.y); y++){

			ALLEGRO_COLOR c1 = color.roof;
			ALLEGRO_COLOR c2 = color.roofD;
			if(y%2 == 0){
				c1 = color.roofD;
				c2 = color.roofDD;
			}
			al_draw_line(top.x,top.y-y,side.x,side.y-y,c1,1);

			al_draw_line(top.x,top.y-y,eX-(side.x-dX),side.y-y,c2,1);
		}
		al_draw_line(top.x,top.y,side.x,side.y,color.roofDD,1);
		al_draw_line(side.x,side.y,side.x,side.y-(top.y-roof.y),color.roofDD,1);
		al_draw_line(side.x,side.y-(top.y-roof.y),roof.x,roof.y,color.roofDD,1);
		al_draw_line(roof.x,roof.y,eX-(side.x-dX),side.y-(top.y-roof.y),color.roofDD,1);
		al_draw_line(eX-(side.x-dX),side.y-(top.y-roof.y),eX-(side.x-dX),side.y,color.roofDD,1);
		al_draw_line(eX-(side.x-dX),side.y,top.x,top.y,color.roofDD,1);
		al_draw_line(top.x,top.y,roof.x,roof.y,color.roofDD,1);
}

void TileDrawer::drawCity(int aLower){

	int s = _tileSize;

	// MIDDLE
	if(aLower == TROPIC || aLower == FOREST || aLower == SCLEROPHYLL){
		// walls backside
		int wallT = randInterval(5,8);
		int wallH = randInterval(5,8);

		al_draw_filled_rectangle(1,1,s,wallT,color.stoneL);
		al_draw_filled_rectangle(1,1,wallT,s-wallH,color.stoneL);
		al_draw_filled_rectangle(s-wallT,1,s,s-wallH,color.stoneL);
		al_draw_filled_rectangle(wallT,wallT,s-wallT,wallT+wallH,color.stone);

		al_draw_line(1,1,s,1,color.stoneD,1);
		al_draw_line(1,1,1,s-2,color.stoneD,1);
		al_draw_line(s,1,s,s-2,color.stoneD,1);
		al_draw_line(wallT,wallT,wallT,s-wallH-wallT,color.stoneD,1);
		al_draw_line(s-wallT,wallT,s-wallT,s-wallH-wallT,color.stoneD,1);
		al_draw_rectangle(wallT,wallT,s-wallT,wallT+wallH,color.stoneD,1);

		al_draw_line(wallT,wallT+wallH+1,wallT+1,s-wallH-wallT,color.shadowL,3);
		al_draw_line(s-wallT-1,wallT+wallH+1,s-wallT-1,s-wallH-wallT,color.shadowL,3);
		al_draw_line(wallT,wallT+wallH+1,s-wallT-1,wallT+wallH+1,color.shadowL,3);

		int minH = wallT;
		int maxH = minH+s/10;
		while(true){
			int w = randInterval(s/3.5,s/2.5);
			int h = w+randInterval(0,s/6);
			int dX = randInterval(wallT,s-w-wallT);
			int dY = randInterval(minH,maxH);
			minH += h/2;
			maxH += h/2;
			if(dY + h > s-wallT) break;
			int eX = dX+w;
			int eY = dY+h;

			Node base1 = {dX+randInterval(w/7,w/4), dY+h/2+randInterval(h/6,h/4)};
			Node base2 = {eX-(base1.x-dX), eY-h/8};
			Node top = {(base1.x+base2.x)/2, base1.y - randInterval(h/6,h/4)};
			Node roof = {top.x,top.y-randInterval(h/3,h/2)};
			Node side = {base1.x-randInterval(w/8,w/10),base1.y+randInterval(w/8,w/10)};

			// shadow
			al_draw_filled_rectangle(base1.x-3,base1.y-3,base2.x+2,base2.y+2,color.shadowLL);
			al_draw_filled_rectangle(base1.x-2,base1.y-2,base2.x+1,base2.y+1,color.shadowLL);

			// stone background
			al_draw_filled_triangle(base1.x,base1.y,top.x,top.y,base2.x,base1.y,color.stoneL);
			al_draw_filled_rectangle(base1.x,base1.y,base2.x,base2.y,color.stoneL);
			ALLEGRO_BITMAP* disp = al_get_target_bitmap();
			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
			for(int x=base1.x; x<=base2.x; x++)
				for(int y=top.y; y<=base2.y; y++){
					if(y%3 == 0 && (rand()%10) > 2) al_put_pixel(x,y,color.stone);
				}
			al_unlock_bitmap(disp);

			// front shading
			ALLEGRO_COLOR cl[3] = {color.houseB,color.stoneD,color.stone};
			for(int i=0; i<3; i++){
				al_draw_line(base1.x+i,base2.y-i,base1.x+i,base1.y,cl[i],1);
				al_draw_line(base1.x+i,base1.y,top.x,top.y+i,cl[i],1);
				al_draw_line(top.x,top.y+i,base2.x-i,base1.y,cl[i],1);
				al_draw_line(base2.x-i,base1.y,base2.x-i,base2.y-i,cl[i],1);
				al_draw_line(base2.x-i,base2.y-i,base1.x+i,base2.y-i,cl[i],1);
			}

			// The Doors
			int doorsW = randInterval(w/6,w/5.5);
			int doorsH = randInterval(h/6,h/5.5);
			al_draw_rectangle(top.x-doorsW/2,base2.y-doorsH,top.x+doorsW/2,base2.y,color.houseB,1);
			al_draw_rectangle(top.x-doorsW/2+1,base2.y-doorsH+1,top.x+doorsW/2-1,base2.y-1,color.doorsD,1);
			al_draw_rectangle(top.x-doorsW/2+2,base2.y-doorsH+2,top.x+doorsW/2-2,base2.y-2,color.doors,1);

			// planks
			float plankX = randInterval(w/6,w/8);
			al_draw_line(base1.x+plankX,top.y,base1.x+plankX,base2.y-1,color.doorsD,1);
			al_draw_line(base2.x-plankX,top.y,base2.x-plankX,base2.y-1,color.doorsD,1);

			// roof
			for(int y=0; y<(top.y-roof.y); y++){

				ALLEGRO_COLOR c1 = color.roof;
				ALLEGRO_COLOR c2 = color.roofD;
				if(y%2 == 0){
					c1 = color.roofD;
					c2 = color.roofDD;
				}
				al_draw_line(top.x,top.y-y,side.x,side.y-y,c1,1);
				al_draw_line(top.x,top.y-y,eX-(side.x-dX),side.y-y,c2,1);
			}
			al_draw_line(top.x,top.y,side.x,side.y,color.roofDD,1);
			al_draw_line(side.x,side.y,side.x,side.y-(top.y-roof.y),color.roofDD,1);
			al_draw_line(side.x,side.y-(top.y-roof.y),roof.x,roof.y,color.roofDD,1);
			al_draw_line(roof.x,roof.y,eX-(side.x-dX),side.y-(top.y-roof.y),color.roofDD,1);
			al_draw_line(eX-(side.x-dX),side.y-(top.y-roof.y),eX-(side.x-dX),side.y,color.roofDD,1);
			al_draw_line(eX-(side.x-dX),side.y,top.x,top.y,color.roofDD,1);
			al_draw_line(top.x,top.y,roof.x,roof.y,color.roofDD,1);
		}

		// walls frontside
		int gate = randInterval(wallT,s-wallT*2-wallH);
		al_draw_filled_rectangle(2,s-wallH-wallT,gate,s-wallH,color.stoneL);
		al_draw_filled_rectangle(0,s-wallH,gate,s-2,color.stone);
		al_draw_filled_rectangle(gate,s-wallH*2,gate+wallT,s-2,color.stone);
		al_draw_filled_rectangle(gate,s-wallH*2-wallT,gate+wallT,s-wallH*2,color.stoneL);

		al_draw_filled_rectangle(gate+wallT*2+wallH,s-wallH-wallT,s-1,s-wallH,color.stoneL);
		al_draw_filled_rectangle(gate+wallT*2+wallH,s-wallH,s,s-2,color.stone);
		al_draw_filled_rectangle(gate+wallT+wallH,s-wallH*2,gate+wallT*2+wallH,s-2,color.stone);
		al_draw_filled_rectangle(gate+wallT+wallH,s-wallH*2-wallT,gate+wallT*2+wallH,s-wallH*2,color.stoneL);

		al_draw_line(s,s-2,gate+wallH+wallT,s-2,color.stoneD,1);
		al_draw_line(gate+wallH+wallT,s-2,gate+wallH+wallT,s-wallH*2,color.stoneD,1);
		al_draw_line(gate+wallH+wallT*2,s-wallH*2,gate+wallH+wallT*2,s-wallH,color.stoneD,1);
		al_draw_line(gate+wallH+wallT*2,s-wallH,s,s-wallH,color.stoneD,1);
		al_draw_line(s,s-wallH,s,s-2,color.stoneD,1);
		al_draw_rectangle(gate+wallH+wallT,s-wallH*2-wallT,gate+wallH+wallT*2,s-wallH*2,color.stoneD,1);
		al_draw_line(s-wallT,s-wallH-wallT,gate+wallH+wallT*2,s-wallH-wallT,color.stoneD,1);

		al_draw_line(1,s-2,gate+wallT,s-2,color.stoneD,1);
		al_draw_line(gate+wallT,s-2,gate+wallT,s-wallH*2,color.stoneD,1);
		al_draw_line(gate,s-wallH*2,gate,s-wallH,color.stoneD,1);
		al_draw_line(gate,s-wallH,1,s-wallH,color.stoneD,1);
		al_draw_line(1,s-wallH,1,s-2,color.stoneD,1);
		al_draw_rectangle(gate,s-wallH*2-wallT,gate+wallT,s-wallH*2,color.stoneD,1);
		al_draw_line(wallT,s-wallH-wallT,gate,s-wallH-wallT,color.stoneD,1);

		al_draw_line(0,s-1,gate+wallT,s-1,color.shadowL,1);
		al_draw_line(0,s,gate+wallT,s,color.shadowLL,1);
		al_draw_line(gate+wallH+wallT,s-1,s,s-1,color.shadowL,1);
		al_draw_line(gate+wallH+wallT,s,s,s,color.shadowLL,1);

		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%3 == 0 && (eq(al_get_pixel(disp,x,y),color.stoneL))) al_put_pixel(x,y,color.stone);
				if(rand()%3 == 0 && (eq(al_get_pixel(disp,x,y),color.stone))) al_put_pixel(x,y,color.stoneD);
			}
		al_unlock_bitmap(disp);
	}

	// WARM
	else if(aLower == SAVANNA || aLower == DESERT || aLower == STEPPE){
		int minH = s/10;
		int maxH = minH+s/10;
		while(true){
			int w = randInterval(s/3,s/2);
			int h = w+randInterval(0,s/6);
			int dX = randInterval(0,s-w);
			int dY = randInterval(minH,maxH);
			minH += h/4;
			maxH += h/4;
			if(dY + h > s) break;
			int eX = dX+w;
			int eY = dY+h;

			Node base1 = {dX+randInterval(w/7,w/4), eY-h/8};
			Node base2 = {eX-(base1.x-dX), dY+h/4+randInterval(h/6,h/4)};
			Node top = {base2.x, base2.y-randInterval(h/5,h/3)};

			// shadow
			al_draw_rectangle(base1.x-2,base1.y-(base2.y-top.y)-2,base2.x+2,base1.y+2,color.shadowLL,1);
			al_draw_rectangle(base1.x-1,base1.y-(base2.y-top.y)-1,base2.x+1,base1.y+1,color.shadowL,1);

			// stone background
			al_draw_filled_rectangle(base1.x,base1.y,base2.x,base2.y,color.stone);
			al_draw_filled_rectangle(base1.x,base2.y,top.x,top.y,color.stoneL);

			// borders
			al_draw_rectangle(base1.x,base1.y,base2.x,base2.y,color.stoneD,1);
			al_draw_rectangle(base1.x,base2.y,top.x,top.y,color.stoneD,1);

			// doors
			int doorsW = h/6;
			int doorsX = randInterval(base1.x+doorsW/2,base2.x-doorsW-doorsW/2);
			if(rand()%10 > 2) al_draw_filled_rectangle(doorsX,base1.y-doorsW*1.5,doorsX+doorsW,base1.y,color.stoneD);

			// first floor
			if(rand()%4 > 0){
				int rw = randInterval(w/4,(base2.x-base1.x)-w/6);
				int rh = randInterval(h/4,(base2.y-top.y)-h/6);
				Node roof1 = {randInterval(base1.x,base2.x-rw),randInterval(base2.y,top.y+rh)};
				Node roof2 = {roof1.x+rw,roof1.y-rh};
				Node peak = {roof2.x,randInterval(roof2.y-h/5,top.y-h/5)};

				al_draw_rectangle(roof1.x-1,roof1.y-(roof2.y-peak.y)-1,roof2.x+1,roof1.y+1,color.shadowLL,1);
				al_draw_filled_rectangle(roof1.x,roof1.y,roof2.x,roof2.y,color.stone);
				al_draw_filled_rectangle(roof1.x,roof2.y,peak.x,peak.y,color.stoneL);
				al_draw_rectangle(roof1.x,roof1.y,roof2.x,roof2.y,color.stoneD,1);
				al_draw_rectangle(roof1.x,roof2.y,peak.x,peak.y,color.stoneD,1);

			}
			ALLEGRO_BITMAP* disp = al_get_target_bitmap();
			al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
			for(int x=0; x<s; x++)
				for(int y=0; y<s; y++){
					if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.stoneL))) al_put_pixel(x,y,color.stone);
					if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.stone))) al_put_pixel(x,y,color.stoneD);
				}
			al_unlock_bitmap(disp);
		}
	}

	// COLD
	if(aLower == TAIGA || aLower == TUNDRA || aLower == POLAR){
		int minH = s/10;
		int maxH = minH+s/10;
		while(true){
			int w = randInterval(s/3,s/2);
			int h = w+randInterval(0,s/6);
			int dX = randInterval(0,s-w);
			int dY = randInterval(minH,maxH);
			minH += h/2;
			maxH += h/2;
			if(dY + h > s) break;
			int eX = dX+w;
			int eY = dY+h;

			Node base1 = {dX+randInterval(w/7,w/4), dY+h/2+randInterval(h/6,h/4)};
			Node base2 = {eX-(base1.x-dX), eY-h/8};
			Node top = {(base1.x+base2.x)/2, base1.y - randInterval(h/6,h/4)};
			Node roof = {top.x,top.y-randInterval(h/3,h/2)};
			Node side = {base1.x-randInterval(w/8,w/10),base1.y+randInterval(w/8,w/10)};

			// shadow
			al_draw_filled_rectangle(base1.x-3,base1.y-3,base2.x+2,base2.y+2,color.shadowLL);
			al_draw_filled_rectangle(base1.x-2,base1.y-2,base2.x+1,base2.y+1,color.shadowLL);

			// front background
			al_draw_filled_triangle(base1.x,base1.y,top.x,top.y,base2.x,base1.y,color.roofDD);
			al_draw_filled_rectangle(base1.x,base1.y,base2.x,base2.y,color.roofDD);

			// front shading
			ALLEGRO_COLOR cl[3] = {color.roofDD,color.roofD,color.roof};
			for(int i=0; i<3; i++){
				al_draw_line(base1.x+i,base2.y-i,base1.x+i,base1.y,cl[i],1);
				al_draw_line(base1.x+i,base1.y,top.x,top.y+i,cl[i],1);
				al_draw_line(top.x,top.y+i,base2.x-i,base1.y,cl[i],1);
				al_draw_line(base2.x-i,base1.y,base2.x-i,base2.y-i,cl[i],1);
				al_draw_line(base2.x-i,base2.y-i,base1.x+i,base2.y-i,cl[i],1);
			}

			// planks
			al_draw_line((base1.x+base2.x)/2,top.y,(base1.x+base2.x)/2,base2.y-1,color.roofL,1);
			al_draw_line(base1.x,base1.y,base2.x,base1.y,color.roofL,1);
			al_draw_line(base1.x,base2.y-h/8,base2.x,base2.y-h/8,color.roofL,1);

			//  hay
			if(rand()%4 > 0){
				int hayW = randInterval(w/6,w/5);
				int hayX = randInterval(base1.x-hayW/2,base2.x+hayW/2);
				al_draw_rectangle(hayX,base2.y-1,hayX+hayW+1,base2.y+hayW+1,color.shadowLL,1);
				al_draw_filled_rectangle(hayX,base2.y-hayW,hayX+hayW,base2.y+hayW,color.mountainGoldL);
				al_draw_filled_rectangle(hayX,base2.y-hayW/3,hayX+hayW,base2.y+hayW/3,color.mountainGoldDD);
			}

			// roof
			for(int y=0; y<(top.y-roof.y); y++){
				ALLEGRO_COLOR c1 = color.mountainGoldLL;
				ALLEGRO_COLOR c2 = color.mountainGoldL;
				if(y%2 == 0){
					c1 = color.mountainGoldL;
					c2 = color.mountainGold;
				}
				al_draw_line(top.x,top.y-y,side.x,side.y-y,c1,1);

				al_draw_line(top.x,top.y-y,eX-(side.x-dX),side.y-y,c2,1);
			}
			al_draw_line(top.x,top.y,side.x,side.y,color.mountainGold,1);
			al_draw_line(side.x,side.y,side.x,side.y-(top.y-roof.y),color.mountainGold,1);
			al_draw_line(side.x,side.y-(top.y-roof.y),roof.x,roof.y,color.mountainGold,1);
			al_draw_line(roof.x,roof.y,eX-(side.x-dX),side.y-(top.y-roof.y),color.mountainGold,1);
			al_draw_line(eX-(side.x-dX),side.y-(top.y-roof.y),eX-(side.x-dX),side.y,color.mountainGold,1);
			al_draw_line(eX-(side.x-dX),side.y,top.x,top.y,color.mountainGold,1);
			al_draw_line(top.x,top.y,roof.x,roof.y,color.mountainGold,1);
		}
	}
}

//*********************************************
//* CITY MAP SPECIFIC
//*********************************************

void TileDrawer::drawWall(bool aConnections[4], int aBiome){
	int s = _tileSize;

	ALLEGRO_COLOR c, cD, cL, cB;
	int mx = 0;

	if(aBiome == TAIGA || aBiome == TUNDRA || aBiome == POLAR){
		c = color.tree;
		cD = color.treeD;
		cL = color.treeL;
		cB = color.treeDD;
		mx = s/5;
	}
	else{
		c = color.stone;
		cD = color.stoneD;
		cL = color.stoneL;
		cB = color.houseB;
		if(aBiome == TROPIC || aBiome == FOREST || aBiome == SCLEROPHYLL) mx = s/7;
	}


	int my = mx*2/3;
	int m2 = my;
	int mid = s/2-3;
	int sh = 3;
	int topBot = mid;
	if(aConnections[3]) topBot = s;

	sRectangle top = {0,0,s,topBot};
	sRectangle front = {0,topBot,s,s-sh};

	drawRect(top,c);
	if(!aConnections[3]) drawRect(front,cD);

	// connections
	if(aConnections[2]){
		al_draw_line(mx,0,mx,my,cB,1);
		al_draw_line(s-mx,0,s-mx,my,cB,1);
	}
	else{
		al_draw_filled_rectangle(mx,my,s-mx,my+m2,cD);
		al_draw_line(mx,my+m2,s-mx,my+m2,cD,1);
		al_draw_line(mx,my,s-mx,my,cB,1);
		al_draw_line(0,1,s,0,cB,1);
	}

	if(aConnections[0]){
		al_draw_filled_rectangle(0,my,mx,my+m2,cD);
		al_draw_line(0,my+m2,mx,my+m2,cD,1);
		al_draw_line(mx,my,mx,my+m2,cD,1);
		al_draw_line(0,my,mx,my,cB,1);
		al_draw_line(0,mid-my,mx,mid-my,cB,1);
	}
	else{
		al_draw_line(mx,my,mx,topBot-my,cB,1);
		al_draw_line(1,0,1,s-sh,cB,1);
	}

	if(aConnections[1]){
		al_draw_filled_rectangle(s,my,s-mx-1,my+m2,cD);
		al_draw_line(s,my+m2,s-mx,my+m2,cD,1);
		al_draw_line(s-mx,my,s-mx,my+m2,cD,1);
		al_draw_line(s,my,s-mx,my,cB,1);
		al_draw_line(s,mid-my,s-mx,mid-my,cB,1);
	}
	else{
		al_draw_line(s-mx,my,s-mx,topBot-my,cB,1);
		al_draw_line(s,0,s,s-sh,cB,1);
	}

	if(aConnections[3]){
		al_draw_line(mx,mid-my,mx,s,cB,1);
		al_draw_line(s-mx,mid-my,s-mx,s,cB,1);
		al_draw_line(1,mid,1,s,cB,1);
		al_draw_line(s,mid,s,s,cB,1);
	}
	else{
		al_draw_line(mx,mid-my,s-mx,mid-my,cB,1);
		al_draw_line(0,s-sh,s,s-sh,cB,1);

		if(aBiome == TROPIC || aBiome == FOREST || aBiome == SCLEROPHYLL){
			// bricks
			int leftX = randInt(s*1/8,s*3/8);
			int rightX = randInt(s*5/8,s*7/8);
			int centerX = randInt(s*3/8,s*5/8);
			al_draw_line(0,mid,s,mid,cB,1);
			al_draw_line(0,mid*1.5,s,mid*1.5,cB,1);
			al_draw_line(leftX,mid,leftX,mid*1.5,cB,1);
			al_draw_line(rightX,mid,rightX,mid*1.5,cB,1);
			al_draw_line(centerX,mid*1.5,centerX,s-sh,cB,1);
			al_draw_line(s,mid*1.5,s,s-sh,cB,1);
		}
		if(aBiome == TAIGA || aBiome == TUNDRA || aBiome == POLAR){
			// woods
			int plankSize = 10;
			for(int y=mid; y<s-sh-plankSize; y+=plankSize){
				al_draw_line(0,y+randInterval(-1,1),s,y+randInterval(-1,1),cB,1+randInterval(0,2));
				if(rand()%5 == 0){
					int x = randInterval(0,s);
					al_draw_line(x+randInterval(-1,1),y,x+randInterval(-1,1),y+plankSize-2,cB,1+randInterval(0,2));
				}
				if(rand()%3 == 0){
					int rx = randInterval(2,5);
					al_draw_filled_ellipse(randInterval(0,s),y-randInterval(0,plankSize-rx),rx,rx/2,cB);
				}
			}
		}

		// shadow
		drawGradient(0,s-sh,s,s,color.shadow,color.blank);
	}

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),c))) al_put_pixel(x,y,cL);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),cD))) al_put_pixel(x,y,c);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawWoodenFloor(){
	int s = _tileSize;
	al_draw_filled_rectangle(0,0,s,s,color.woodL);

	// planks
	int pX = 0;
	int pY = 0;
	int d = s/2;
	ALLEGRO_COLOR c[2] = {color.woodD, color.woodDD};
	for(int i=0; i<4; i++){
		al_draw_line(pX,				pY,				pX+d/2,		pY+d/2,	c[rand()%2],1);
		al_draw_line(pX+d/2,		pY,				pX+d,			pY+d/2,	c[rand()%2],1);
		al_draw_line(pX+d/4,		pY+d*3/4,	pX+d/2,		pY+d,		c[rand()%2],1);
		al_draw_line(pX+d*3/4,	pY+d*3/4,	pX+d,			pY+d,		c[rand()%2],1);

		al_draw_line(pX,				pY+d/2,		pX+d/4,		pY+d/4,	c[rand()%2],1);
		al_draw_line(pX,				pY+d,			pX+d*3/4,	pY+d/4,	c[rand()%2],1);
		al_draw_line(pX+d/2,		pY+d,			pX+d,			pY+d/2,	c[rand()%2],1);

		switch(i){
		case 0: pX+=s/2; break;
		case 1: pY+=s/2; pX=0; break;
		case 2: pX+=s/2; break;
		}
	}

	int holes = randInt(0,3);
	for(int i=0; i<holes; i++) al_draw_filled_circle(randInterval(0,s),randInterval(0,s),randInterval(1,2),color.woodD);

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.woodL))) al_put_pixel(x,y,color.woodD);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawCarpetFloor(){
	al_draw_filled_rectangle(0,0,s,s,color.carpet);

	int r = 6;
	int mr = 12;

	al_draw_circle(0,0,s/2,color.carpetL,1);
	al_draw_circle(0,s,s/2,color.carpetL,1);
	al_draw_circle(s,0,s/2,color.carpetL,1);
	al_draw_circle(s,s,s/2,color.carpetL,1);
	al_draw_circle(0,0,s/r,color.carpetL,1);
	al_draw_circle(0,s,s/r,color.carpetL,1);
	al_draw_circle(s,0,s/r,color.carpetL,1);
	al_draw_circle(s,s,s/r,color.carpetL,1);
	al_draw_filled_circle(0,0,s/mr,color.carpetL);
	al_draw_filled_circle(0,s,s/mr,color.carpetL);
	al_draw_filled_circle(s,0,s/mr,color.carpetL);
	al_draw_filled_circle(s,s,s/mr,color.carpetL);

	al_draw_circle(s/2,s/2,s/2,color.carpetL,1);
	al_draw_circle(s/2,s/2,s/r,color.carpetL,1);
	al_draw_filled_circle(s/2,s/2,s/mr,color.carpetL);

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%4 == 0 && (eq(al_get_pixel(disp,x,y),color.carpet))) al_put_pixel(x,y,color.carpetD);
				else if(rand()%4 == 0 && (eq(al_get_pixel(disp,x,y),color.carpetL))) al_put_pixel(x,y,color.carpet);
				else if(rand()%4 == 0 && (eq(al_get_pixel(disp,x,y),color.gold))) al_put_pixel(x,y,color.carpetL);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawMarketFloor(){
	int s = _tileSize;
	al_draw_filled_rectangle(0,0,s,s,color.pavementL);

	// planks
	int pX = 0;
	int pY = 0;
	int d = s/2;
	float a = s/8;
	ALLEGRO_COLOR c[2] = {color.pavement, color.pavementD};
	for(int i=0; i<4; i++){

		if(rand()%1 == 0){
			int sx = pX+d/4;
			int sy = pY+d*3/4;
			for(int x=0; x<a; x++){
				al_draw_line(sx+x,sy+x,sx+x+2*a,sy+x-2*a,color.pavement,2);
			}
		}
		al_draw_line(pX,				pY,				pX+d/2,		pY+d/2,	c[rand()%2],1);
		al_draw_line(pX+d/2,		pY,				pX+d,			pY+d/2,	c[rand()%2],1);
		al_draw_line(pX+d/4,		pY+d*3/4,	pX+d/2,		pY+d,		c[rand()%2],1);
		al_draw_line(pX+d*3/4,	pY+d*3/4,	pX+d,			pY+d,		c[rand()%2],1);

		al_draw_line(pX,				pY+d/2,		pX+d/4,		pY+d/4,	c[rand()%2],1);
		al_draw_line(pX,				pY+d,			pX+d*3/4,	pY+d/4,	c[rand()%2],1);
		al_draw_line(pX+d/2,		pY+d,			pX+d,			pY+d/2,	c[rand()%2],1);

		switch(i){
		case 0: pX+=s/2; break;
		case 1: pY+=s/2; pX=0; break;
		case 2: pX+=s/2; break;
		}
	}

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%10 == 0 && (eq(al_get_pixel(disp,x,y),color.pavementL))) al_put_pixel(x,y,color.pavement);
				if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.pavement))) al_put_pixel(x,y,color.pavementL);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawCubePattern(int aX, int aY){
	int s = _tileSize;
	int rh = s/3;
	int w = s/2;
	int h = (s-rh)/2;

	int l = aX-w/2;
	int m = aX;
	int r = aX+w/2;
	int t = aY;
	int mt = aY+rh/2;
	int mm = aY+rh;
	int mb = aY+rh/2+h;
	int b = aY+rh+h;

	al_draw_filled_triangle(l,mt,l,mb,m,mm, color.pavement);
	al_draw_filled_triangle(r,mt,r,mb,m,mm, color.pavementL);
	al_draw_filled_triangle(m,b,l,mb,m,mm, color.pavement);
	al_draw_filled_triangle(m,b,r,mb,m,mm, color.pavementL);
	al_draw_filled_triangle(m,t,l,mt,m,mm,color.pavementD);
	al_draw_filled_triangle(m,t,r,mt,m,mm,color.pavementD);

	/*
	al_draw_line(m,t,l,mt,col[rand()%2],1);
	al_draw_line(l,mt,m,mm,col[rand()%2],1);
	al_draw_line(m,mm,r,mt,col[rand()%2],1);
	al_draw_line(r,mt,m,t,col[rand()%2],1);

	al_draw_line(l,mt,l,mb,col[rand()%2],1);
	al_draw_line(m,mm,m,b,col[rand()%2],1);
	al_draw_line(r,mt,r,mb,col[rand()%2],1);
	al_draw_line(l,mb,m,b,col[rand()%2],1);
	al_draw_line(r,mb,m,b,col[rand()%2],1);*/
}

void TileDrawer::drawTempleFloor(){
	int s = _tileSize;
	int rh = s/3;
	int w = s/2;
	int h = (s-rh)/2;

	al_draw_filled_rectangle(0,0,s,s,color.pavement);

	drawCubePattern(w/2,-rh);
	drawCubePattern(w+w/2,-rh);
	drawCubePattern(0,h-rh/2);
	drawCubePattern(w,h-rh/2);
	drawCubePattern(w*2,h-rh/2);
	drawCubePattern(w/2,2*h);
	drawCubePattern(w+w/2,2*h);

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pavementL))) al_put_pixel(x,y,color.pavement);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pavementD))) al_put_pixel(x,y,color.pavement);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pavement))) al_put_pixel(x,y,color.pavementL);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pavement))) al_put_pixel(x,y,color.pavementD);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawBedSide(int aY){
	int mx = 10;
	int poleW = s/8;
	int poleZ = poleW*3/4;
	int poleH = poleW*3;

	// shadow
	drawGradient(mx,aY+poleH-poleZ/2,s-mx,aY+poleH+poleZ/2,color.black,color.blank);

	// poles in corners
	al_draw_filled_rectangle(mx,aY,mx+poleW,aY+poleH,color.tree);
	al_draw_filled_rectangle(s-mx-poleW,aY,s-mx,aY+poleH,color.tree);
	al_draw_filled_rectangle(mx,aY,mx+poleW,aY+poleZ,color.treeL);
	al_draw_filled_rectangle(s-mx-poleW,aY,s-mx,aY+poleZ,color.treeL);

	al_draw_rectangle(mx,aY,mx+poleW,aY+poleH,color.treeDD,1);
	al_draw_rectangle(s-mx-poleW,aY,s-mx,aY+poleH,color.treeDD,1);
	al_draw_line(mx,aY+poleZ,mx+poleW,aY+poleZ,color.treeDD,1);
	al_draw_line(s-mx-poleW,aY+poleZ,s-mx,aY+poleZ,color.treeDD,1);

	// plank
	al_draw_filled_rectangle(mx+poleW,aY+poleZ/2,s-mx-poleW,aY+poleH-poleZ/2,color.tree);
	al_draw_filled_rectangle(mx+poleW,aY+poleZ/2,s-mx-poleW,aY+poleZ,color.treeL);
	al_draw_rectangle(mx+poleW,aY+poleZ/2,s-mx-poleW,aY+poleH-poleZ/2,color.treeDD,1);
	al_draw_rectangle(mx+poleW,aY+poleZ/2,s-mx-poleW,aY+poleZ,color.treeDD,1);
}

void TileDrawer::drawBed(bool aBegin, int aDir){
	int mx = 10;
	int poleW = s/8;
	int poleZ = poleW*3/4;
	int poleH = poleW*3;
	int my = 15;
	if(aDir == UP || aDir == DOWN){
		my = 5;
		mx = 20;
	}
	int pillowY = my+poleH*3/2;

	if(aBegin){
		if(aDir == LEFT || aDir == RIGHT){
			drawBedSide(my);

			al_draw_filled_rectangle(mx+poleW/2,my+poleH/2,s-mx-poleW/2,s,color.pillowL);
			al_draw_rectangle(mx+poleW/2,my+poleH/2,s-mx-poleW/2,s,color.pillowDD,1);

			al_draw_filled_rounded_rectangle(mx+poleW/2-1,my+poleH*3/4,s-mx-poleW/2+1,s+s/4,10,10,color.pillow);
			al_draw_rounded_rectangle(mx+poleW/2-1,my+poleH*3/4,s-mx-poleW/2+1,s+s/4,10,10,color.pillowDD,1);

			al_draw_filled_ellipse(s/2,pillowY,s/2-mx-poleW/2+2,10,color.pillowD);
			al_draw_ellipse(s/2,pillowY,s/2-mx-poleW/2+2,10,color.pillowDD,1);

			al_draw_filled_rectangle(mx+poleW/2-1,pillowY,s-mx-poleW/2+1,s,color.pillowD);
		}
		else{
			drawGradient(mx,s-my-poleZ/2,s,s-my+poleZ/2,color.black,color.blank);

			al_draw_filled_rectangle(mx,my,mx+poleW,s-my,color.tree);
			al_draw_filled_rectangle(mx,my,mx+poleW,my+poleZ,color.treeL);
			al_draw_filled_rectangle(mx,my+poleZ+poleW,mx+poleW,s-my-poleH,color.treeL);

			al_draw_rectangle(mx,my,mx+poleW,s-my,color.treeDD,1);
			al_draw_rectangle(mx,my+poleZ,mx+poleW,my+poleZ+poleW,color.treeDD,1);
			al_draw_rectangle(mx,s-my-poleH-poleZ,mx+poleW,s-my-poleH,color.treeDD,1);

			// pillow
			al_draw_filled_rectangle(mx+poleW,my+poleW,s,s-my-poleZ/2,color.pillowL);
			al_draw_rectangle(mx+poleW+1,my+poleW,s+2,s-my-poleZ/2,color.pillowDD,1);

			al_draw_filled_rectangle(mx+poleW,my+poleW,s,s-my-poleZ,color.pillowD);
			al_draw_rectangle(mx+poleW+1,my+poleW,s+2,s-my-poleZ,color.pillowDD,1);
			al_draw_line(mx+poleW+1,s-my-poleH+poleZ/2,s+2,s-my-poleH+poleZ/2,color.pillowDD,1);
		}
	}
	else{
		if(aDir == LEFT || aDir == RIGHT){
			// pillow
			al_draw_filled_rectangle(mx+poleW/2-1,0,s-mx-poleW/2+2,s/2-my+poleZ,color.pillowD);
			al_draw_rectangle(mx+poleW/2-1,-2,s-mx-poleW/2+2,s/2-my+poleZ,color.pillowDD,1);

			drawBedSide(s/2-my);
		}
		else{
			drawGradient(0,s-my-poleZ/2,s-mx,s-my+poleZ/2,color.black,color.blank);

			al_draw_filled_rectangle(s-mx-poleW,my,s-mx,s-my,color.tree);
			al_draw_filled_rectangle(s-mx-poleW,my,s-mx,my+poleZ,color.treeL);
			al_draw_filled_rectangle(s-mx-poleW,my+poleZ+poleW,s-mx,s-my-poleH,color.treeL);

			al_draw_rectangle(s-mx-poleW,my,s-mx,s-my,color.treeDD,1);
			al_draw_rectangle(s-mx-poleW,my+poleZ,s-mx,my+poleZ+poleW,color.treeDD,1);
			al_draw_rectangle(s-mx-poleW,s-my-poleH-poleZ,s-mx,s-my-poleH,color.treeDD,1);

			// pillow
			al_draw_filled_rectangle(0,my+poleW,s-mx-poleW-1,s-my-poleZ/2,color.pillowL);
			al_draw_rectangle(-2,my+poleW,s-mx-poleW-1,s-my-poleZ/2,color.pillowDD,1);
			al_draw_line(0,s-my-poleH+poleZ/2,s-mx-poleW-2,s-my-poleH+poleZ/2,color.pillow,1);

			al_draw_filled_rounded_rectangle(0,my+poleW,s-mx-poleW-poleZ,s-my-poleH+poleZ/2,10,10,color.pillow);
			al_draw_rounded_rectangle(0,my+poleW,s-mx-poleW-poleZ,s-my-poleH+poleZ/2,10,10,color.pillowDD,1);

			int circleX = s-mx-poleW-poleZ*5;
			int circleY = s-my-poleZ-poleW;
			al_draw_filled_circle(circleX,circleY,poleW,color.pillowD);
			al_draw_circle(circleX,circleY,poleW,color.pillowDD,1);
			al_draw_filled_rectangle(0,my+poleW,circleX+poleW,circleY,color.pillowD);
			al_draw_filled_rectangle(0,circleY,circleX,circleY+poleW,color.pillowD);
			al_draw_line(0,my+poleW,circleX+poleW,my+poleW,color.pillowDD,1);
			al_draw_line(0,s-my-poleH+poleZ/2,circleX+poleW,s-my-poleH+poleZ/2,color.pillowDD,1);
			al_draw_line(0,s-my-poleZ,circleX,s-my-poleZ,color.pillowDD,1);
			al_draw_line(circleX+poleW,my+poleW,circleX+poleW,circleY,color.pillowDD,1);
		}
	}

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.treeL))) al_put_pixel(x,y,color.tree);
				if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.treeD))) al_put_pixel(x,y,color.tree);
				if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.tree))) al_put_pixel(x,y,color.treeL);
				if(rand()%20 == 0 && (eq(al_get_pixel(disp,x,y),color.tree))) al_put_pixel(x,y,color.treeD);

				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pillowL))) al_put_pixel(x,y,color.pillow);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pillow))) al_put_pixel(x,y,color.pillowD);
				if(rand()%40 == 0 && (eq(al_get_pixel(disp,x,y),color.pillowD))) al_put_pixel(x,y,color.pillowDD);
			}
		al_unlock_bitmap(disp);
}

void TileDrawer::drawOven(bool aBegin, int aDir){
	int mx = 30;
	int my = 10;

	int top = s/2;
	int dif = s/20;
	int l = s-(mx+dif);
	int d = l/10;

	if(aDir == LEFT || aDir == RIGHT){
		mx = 15;
		my = 25;
		top = s/3;
	}

	if(aBegin){
		if(aDir == LEFT || aDir == RIGHT){
			my = s/2;
			// top
			al_draw_filled_rounded_rectangle(mx,my,s-mx,s+s/4,3,3,color.iron);
			al_draw_rounded_rectangle(mx,my,s-mx,s+s/4,3,3,color.ironDD,1);

			int hl = s-mx*2;
			al_draw_ellipse(mx+hl*1/4,s-hl/4,hl/5,hl/8,color.ironD,1);
			al_draw_ellipse(mx+hl*3/4,s-hl/4,hl/5,hl/8,color.ironD,1);

			int chimneyW = hl/5.5;
			int chimneyZ = hl/10;
			int step = s/20;
			for(int y=my+chimneyZ*2; y>chimneyZ; y-=step){
				al_draw_filled_ellipse(mx+hl/3,y,chimneyW,chimneyZ,color.ironD);
				al_draw_ellipse(mx+hl/3,y,chimneyW,chimneyZ,color.ironDD,1);
				al_draw_filled_rectangle(mx+hl/3-chimneyW,y,mx+hl/3+chimneyW,y-step,color.ironD);
			}
			al_draw_filled_ellipse(mx+hl/3,chimneyZ,chimneyW,chimneyZ,color.black);

			al_draw_filled_ellipse(mx+hl*3/4,my+chimneyZ*2,chimneyW,chimneyZ,color.ironD);
		}
		else{
			drawGradient(mx+dif,s-my,s,s-my/4,color.black,color.blank);

			// bot
			al_draw_filled_rectangle(mx+dif,top,s,s-my,color.ironD);
			al_draw_rectangle(mx+dif,top,s+2,s-my,color.ironDD,1);

			al_draw_filled_triangle(mx+dif,s-my,mx+dif,s-my/2,mx+dif+my/2,s-my,color.ironDD);

			if(aDir == DOWN){
				al_draw_filled_rectangle(mx+dif+d,top+d,mx+dif+l/2-d,top+d*2,color.iron);
				al_draw_rectangle(mx+dif+d,top+d,mx+dif+l/2-d,top+d*2,color.ironDD,1);
				al_draw_filled_rectangle(mx+dif+d,s-my-d,mx+dif+l/2-d,s-my-d*2,color.iron);
				al_draw_rectangle(mx+dif+d,s-my-d,mx+dif+l/2-d,s-my-d*2,color.ironDD,1);
				al_draw_filled_rectangle(mx+dif+l/2+d,top+d,s-d,s-my-d,color.iron);
				al_draw_rectangle(mx+dif+l/2+d,top+d,s-d,s-my-d,color.ironDD,1);
				al_draw_line(mx+dif+l/2+d/2,top+(s-my-top)/2,mx+dif+l/2+d*3/2,top+(s-my-top)/2,color.ironDD,2);
			}

			// top
			al_draw_filled_rounded_rectangle(mx,my,s+s/4,top,3,3,color.iron);
			al_draw_rounded_rectangle(mx,my,s+s/4,top,3,3,color.ironDD,1);

			int vl = top - my;
			al_draw_ellipse(mx+dif+l*3/4,my+vl/4,l/4,vl/6,color.ironD,1);
			al_draw_ellipse(mx+dif+l*3/4,my+vl*3/4,l/4,vl/6,color.ironD,1);

			int chimneyW = l/6;
			int chimneyZ = vl/6;
			int step = s/20;
			for(int y=my+vl*3/4; y>chimneyZ; y-=step){
				al_draw_filled_ellipse(mx+dif+l/6,y,chimneyW,chimneyZ,color.ironD);
				al_draw_ellipse(mx+dif+l/6,y,chimneyW,chimneyZ,color.ironDD,1);
				al_draw_filled_rectangle(mx+dif+l/6-chimneyW,y,mx+dif+l/6+chimneyW,y-step,color.ironD);
			}
			al_draw_filled_ellipse(mx+dif+l/6,chimneyZ,chimneyW,chimneyZ,color.black);
		}
	}
	else{
		if(aDir == LEFT || aDir == RIGHT){
			drawGradient(mx+dif,s-my,s-mx-dif,s-my+dif*2,color.black,color.blank);

			// bot
			al_draw_filled_rectangle(mx+dif,top,s-mx-dif,s-my,color.ironD);
			al_draw_rectangle(mx+dif,top,s-mx-dif,s-my,color.ironDD,1);

			al_draw_filled_triangle(mx+dif,s-my,mx+dif,s-my+dif*2,mx+dif+my/2,s-my-dif/2,color.ironDD);
			al_draw_filled_triangle(s-mx-dif,s-my,s-mx-dif,s-my+dif*2,s-mx-dif-my/2,s-my-dif/2,color.ironDD);

			al_draw_line(mx+dif+d*2,top+d*2,s-mx-dif-d*2,top+d*2,color.ironDD,3);
			al_draw_line(mx+dif+d*2,s-my-d*2,s-mx-dif-d*2,s-my-d*2,color.ironDD,3);
			
			// top
			al_draw_filled_rounded_rectangle(mx,-s/4,s-mx,top,3,3,color.iron);
			al_draw_rounded_rectangle(mx,-s/4,s-mx,top,3,3,color.ironDD,1);

			int hl = s-mx*2;
			al_draw_ellipse(mx+hl*1/4,top/2,hl/5,hl/8,color.ironD,1);
			al_draw_ellipse(mx+hl*3/4,top/2,hl/5,hl/8,color.ironD,1);
		}
		else{
			drawGradient(s-mx-dif,s-my,0,s-my/4,color.black,color.blank);

			// bot
			al_draw_filled_rectangle(-2,top,s-mx-dif,s-my,color.ironD);
			al_draw_rectangle(-2,top,s-mx-dif,s-my,color.ironDD,1);

			al_draw_filled_triangle(s-mx-dif,s-my,s-mx-dif,s-my/2,s-(mx+dif+my/2),s-my,color.ironDD);

			if(aDir == DOWN){
				al_draw_filled_rectangle(d,top+d,s-mx-dif-d,s-my-d,color.iron);
				al_draw_rectangle(d,top+d,s-mx-dif-d,s-my-d,color.ironDD,1);
				al_draw_filled_rectangle(d*2,top+d+d/2,s-mx-dif-d*2,top+d+d,color.ironD);
				al_draw_rectangle(d*2,top+d+d/2,s-mx-dif-d*2,top+d+d,color.ironDD,1);
			}

			// top
			al_draw_filled_rounded_rectangle(-s/4,my,s-mx,top,2,2,color.iron);
			al_draw_rounded_rectangle(-s/4,my,s-mx,top,2,2,color.ironDD,1);

			int vl = top - my;
			al_draw_ellipse(s-(mx+dif+l/2),my+vl/4,l/4,vl/6,color.ironD,1);
			al_draw_ellipse(s-(mx+dif+l/2),my+vl*3/4,l/4,vl/6,color.ironD,1);
		}
	}

	noise(color.iron,color.ironD,15);
	noise(color.ironD,color.ironDD,15);
}

void TileDrawer::drawBookcase(bool aBegin, int aDir){
	int mx = 10;
	int my = 5;
	int top = my*4;
	int d = 3;
	int b = 4;
	int mid = (top+(s-my))/2;

	if(aDir == LEFT || aDir == RIGHT){
		int mx2 = mx*2;
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		if(aBegin){
			// top
			draw_rectangle(mx,my*2,s-mx2,s+2,color.treeL,color.treeDD,1);
		}
		else{
			drawGradient(mx,s-my,s-mx2,s-my+top/4,color.shadowL,color.blank);

			// bot
			draw_rectangle(mx,top,s-mx2,s-my,color.tree,color.treeDD,1);

			// top
			draw_rectangle(mx,-2,s-mx2,top,color.treeL,color.treeDD,1);
		}

		al_set_target_bitmap(disp);
		if(aDir == RIGHT) al_draw_bitmap(buffer,0,0,0);
		else al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
	}
	else{
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		drawGradient(mx-1,s-my,s,s-my+top/4,color.shadowL,color.blank);

		// bot
		draw_rectangle(mx,top,s+2,s-my,color.tree,color.treeDD,1);
	
		if(aDir == DOWN){
			// books
			draw_rectangle(mx+d,top+d,s+2,mid-d/2,color.treeD,color.treeDD,1);
			draw_rectangle(mx+d,mid+d/2,s+2,s-my-d,color.treeD,color.treeDD,1);
			ALLEGRO_COLOR col[9] = {color.carpetD,color.bananaDD,color.ironD,color.leafDD,color.bridgeD,
															color.doorsD,color.houseB,color.mountainGoldDD,color.pillowDD};
			int y1 = top+d;
			int y2 = mid-d/2;
			for(int i=0; i<2; i++){
				for(int x=mx+d; x<s; x+=b){
					if(rand()%2 == 0){
						al_draw_filled_rectangle(x,y1,x+b,y2-1,col[rand()%9]);
						al_draw_line(x,y1+1,x+b,y1+1,color.snow,1);
					}
					else al_draw_filled_rectangle(x,y1,x+b,y2-2,col[rand()%9]);
					al_draw_line(x+1,y1,x+1,y2-1,color.shadowL,1);
					al_draw_line(x+b,y1,x+b-1,y2-1,color.shadowL,1);
				}
				y1 = mid+d/2;
				y2 = s-my-d;
			}
		}

		// top
		draw_rectangle(mx,my,s+2,top,color.treeL,color.treeDD,1);

		al_set_target_bitmap(disp);
		if(aBegin) al_draw_bitmap(buffer,0,0,0);
		else al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
	}

	noise(color.treeL,color.tree,15);
	noise(color.tree,color.treeL,15);
}

void TileDrawer::drawFurnace(bool aBegin, int aDir){
	int mx = 20;
	int my = 5;
	int mMy = s*1/3;
	int mTop = s*2/3;
	int top = (mTop-mMy)+my;
	int d = 5;
	int lm = (s-mx)/2;

	if(aDir == LEFT || aDir == RIGHT){
		mx = 17;
		my = 10;
		if(aBegin){
			lm = s/2;

			// bot
			draw_rectangle(mx,mTop+my,s-mx,s,color.mountain,color.mountainDD,1);

			// top
			draw_rectangle(mx,my,s-mx,mTop+my,color.mountainL,color.mountainDD,1);
			drawGradient(lm-d*1.5,top-d,lm+d*1.5+1,top,color.shadowL,color.blank);
			draw_rectangle(lm-d*1.5,0,lm+d*1.5,top-d,color.mountain,color.mountainDD,1);
			draw_rectangle(lm-d*1.5,0,lm+d*1.5,my,color.ironDD,color.mountainDD,1);

		}
		else{
			drawGradient(mx,s-my,s-mx,s-my+my/2,color.shadowL,color.blank);

			// bot
			draw_rectangle(mx,mTop,s-mx,s-my,color.mountain,color.mountainDD,1);

			// top
			draw_rectangle(mx,0,s-mx,mTop,color.mountainL,color.mountainDD,1);
			draw_rectangle(mx+d,d,s-mx-d,mTop-d,color.carpetD,color.mountainDD,1);
		}
	}
	else{
		if(aBegin){
			drawGradient(mx-1,s-my,s,s,color.shadowL,color.blank);

			// bot
			draw_rectangle(mx,mTop,s+2,s-my,color.mountain,color.mountainDD,1);

			// top
			draw_rectangle(mx,mMy,s,mTop,color.mountainL,color.mountainDD,1);
			draw_rectangle(mx+d,mMy+d,s-d,mTop-d,color.carpetD,color.mountainDD,1);
		}
		else{
			drawGradient(-2,s-my,s-mx,s,color.shadowL,color.blank);

			// bot
			draw_rectangle(-2,top,s-mx,s-my,color.mountain,color.mountainDD,1);

			// top
			draw_rectangle(0,my,s-mx,top,color.mountainL,color.mountainDD,1);
			al_draw_line(1,my,1,top,color.mountainDD,1);
			drawGradient(lm-d*1.5,top-d,lm+d*1.5+1,top-1,color.shadowL,color.blank);
			draw_rectangle(lm-d*1.5,0,lm+d*1.5,top-d,color.mountain,color.mountainDD,1);
			draw_rectangle(lm-d*1.5,0,lm+d*1.5,my*2,color.ironDD,color.mountainDD,1);

			if(aDir == DOWN){
				al_draw_filled_ellipse((s-mx)/2,(mTop+top)/2,15,6,color.ironDD);
				al_draw_ellipse((s-mx)/2,(mTop+top)/2,15,6,color.mountainDD,1);
				draw_rectangle((s-mx)/2-15,(mTop+top)/2,(s-mx)/2+15,mTop,color.ironDD,color.mountainDD,1);
				draw_rectangle((s-mx)/2-15,s-my-d*2,(s-mx)/2+15,s-my-d,color.ironDD,color.mountainDD,1);
				al_draw_line((s-mx)/2-15,(mTop+top)/2,(s-mx)/2+14,(mTop+top)/2,color.ironDD,1);
			}
		}
	}

	noise(color.mountainD,color.mountainDD,3);
	noise(color.mountain,color.mountainD,3);
	noise(color.mountainL,color.mountain,3);

	noise(color.carpetD,color.banana,3);

	noise(color.mountainL,color.pavement,1);
	noise(color.mountain,color.pavementD,1);
	noise(color.mountainD,color.pavementDD,1);
	//noise(color.mountainDD,color.mountainD,1);

}

void TileDrawer::drawHerbstand(bool aBegin, int aDir){
	int mx = 10;
	int my = 10;
	int d = 5;
	int b = 8;

	if(aDir == LEFT || aDir == RIGHT){
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		if(aBegin){
			// herbs
			for(int y=my+d; y<s; y+=b){
				int h = randInterval(5,10);
				int r = randInterval(4,7);

				al_draw_filled_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leaf);
				al_draw_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leafDD,2);
				al_draw_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leaf,1);
			}

			draw_rectangle(s/2-d/2,my,s/2+d/2,my+d,color.treeL,color.treeDD,1);
			draw_rectangle(s/2-d/2,my+d,s/2+d/2,s+2,color.treeL,color.treeDD,1);
		}
		else{
			// herbs
			for(int y=0; y<s-my-d*2; y+=b){
				int h = randInterval(5,10);
				int r = randInterval(4,7);

				al_draw_filled_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leaf);
				al_draw_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leafDD,2);
				al_draw_triangle(s/2,y,s/2-r,y+h,s/2+r,y+h,color.leaf,1);
			}

			drawGradient(s/2-d/2-1,s-my,s/2+d/2,s-my+my/2,color.shadowL,color.blank);

			draw_rectangle(s/2-d/2,my+d,s/2+d/2,s-my,color.tree,color.treeDD,1);
			draw_rectangle(s/2-d/2,my,s/2+d/2,my+d,color.treeL,color.treeDD,1);
			draw_rectangle(s/2-d/2,-2,s/2+d/2,my,color.treeL,color.treeDD,1);
		}

		noise(color.leaf,color.blank,5);
		noise(color.leaf,color.leafD,3);
		noise(color.leaf,color.leafL,3);

		al_set_target_bitmap(disp);
		al_draw_bitmap(buffer,0,0,0);
	}
	else{
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		drawGradient(mx-1,s-my,mx+d,s-my+my/2,color.shadowL,color.blank);

		// pole
		draw_rectangle(mx,my+d,mx+d,s-my,color.tree,color.treeDD,1);
		draw_rectangle(mx,my,mx+d,my+d,color.treeL,color.treeDD,1);
		draw_rectangle(mx+d,my,s+2,my+d,color.treeL,color.treeDD,1);
		draw_rectangle(mx+d,my+d,s+1,my+d*1.5,color.tree,color.treeDD,1);
	
		// herbs
		for(int x=mx+b; x<s-b/2; x+=b){
			int line = randInterval(my+d*2,s/2);
			int bot = randInterval(line+d*2,line+s/2-d);
			int bound = randInterval(line+d,bot-d);
			int r = randInterval(b/4,b/2);

			al_draw_line(x,my,x,line,color.ironD,1);
			al_draw_filled_triangle(x,bound,x-r/2,line,x+r/2,line,color.leaf);
			al_draw_filled_triangle(x,bound,x-r,bot,x+r,bot,color.leaf);
			al_draw_triangle(x,bound,x-r/2,line,x+r/2,line,color.leafDD,2);
			al_draw_triangle(x,bound,x-r,bot,x+r,bot,color.leafDD,2);
			al_draw_triangle(x,bound,x-r/2,line,x+r/2,line,color.leaf,1);
			al_draw_triangle(x,bound,x-r,bot,x+r,bot,color.leaf,1);
		}

		noise(color.leaf,color.blank,5);
		noise(color.leaf,color.leafD,3);
		noise(color.leaf,color.leafL,3);

		al_set_target_bitmap(disp);
		if(aBegin) al_draw_bitmap(buffer,0,0,0);
		else al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
	}
}

void TileDrawer::drawReception(bool aBegin, int aDir){
	int mx = 17;
	int my = 13;
	int top = 15;
	int d = 3;
	int b = 4;
	int mid = s/2+5;

	if(aDir == LEFT || aDir == RIGHT){
		int mx2 = mx*2;

		if(aBegin){
			al_draw_filled_rounded_rectangle(mx,my,s-mx,s*2,18,12,color.treeL);
			al_draw_rounded_rectangle(mx,my,s-mx,s*2,18,12,color.treeDD,1);
		}
		else{
			for(int i=1; i<8; i+=2) al_draw_filled_ellipse(s/2,s-my-10,8+i,8+i,color.shadowLL);

			al_draw_filled_rounded_rectangle(mx,-s,s-mx,s-my,18,12,color.tree);
			al_draw_rounded_rectangle(mx,-s,s-mx,s-my,18,12,color.treeDD,1);
			al_draw_filled_rounded_rectangle(mx,-s,s-mx,s-my-top,18,12,color.treeL);
			al_draw_rounded_rectangle(mx,-s,s-mx,s-my-top,18,12,color.treeDD,1);
		}
	}
	else{
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		drawGradient(mx+10,s-my,s,s-my+3,color.shadowL,color.blank);

		// top
		al_draw_filled_rounded_rectangle(mx,s-mid,s*2,s-my,18,12,color.tree);
		al_draw_rounded_rectangle(mx,s-mid,s*2,s-my,18,12,color.treeDD,1);

		al_draw_filled_rectangle(mx,(my+mid)/2,s,((s-mid)+(s-my))/2,color.tree);
		al_draw_line(mx,(my+mid)/2,mx,((s-mid)+(s-my))/2,color.treeDD,1);

		al_draw_filled_rounded_rectangle(mx,my,s*2,mid,18,12,color.treeL);
		al_draw_rounded_rectangle(mx,my,s*2,mid,18,12,color.treeDD,1);
	

		al_set_target_bitmap(disp);
		if(aBegin) al_draw_bitmap(buffer,0,0,0);
		else al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
	}

	noise(color.treeL,color.tree,15);
	noise(color.tree,color.treeL,15);
}

void TileDrawer::drawAltar(bool aCenter, int aDir){
	int mx = 20;
	int my = 10;
	int top = 30;
	int bot = 45;

	if(aCenter){
		if(aDir == LEFT){
			// shadow
			drawGradient(0,top,s,s-my,color.black,color.blank);

			// tablecloth
			draw_rectangle(-2,my,s+2,top,color.clothLL,color.clothD,1);
			int y;
			for(int x=0; x<s; x++){
				y = bot + sin(x/2.0)*2;
				al_draw_line(x,y-1,x+1,y-4,color.clothL,1);
				al_draw_line(x,y,x+1,y,color.clothD,1);
			}
			al_draw_filled_rectangle(0,top,s,bot-3,color.clothL);

			// book
			draw_rectangle(mx,my+3,s-mx,(my+top)/2+2,color.carpet,color.carpetD,1);
			draw_rectangle(mx+2,my+5,s-mx-2,(my+top)/2,color.carpet,color.carpetL,1);
			draw_rectangle(mx,(my+top)/2+2,s-mx,top-3,color.snow,color.snowDD,1);
			draw_rectangle(mx+1,(my+top)/2+3,s-mx-1,top-4,color.snow,color.snowD,1);
			al_draw_line(mx+4,(my+top)/2+3,mx+3,(my+top)/2+9,color.carpet,2);
		}
		else{
			// tablecloth
			draw_rectangle(my,-2,s-my,s+2,color.clothLL,color.clothD,1);

			// book
			draw_rectangle(mx,my+3,s-mx,(my+top)/2+2,color.carpet,color.carpetD,1);
			draw_rectangle(mx+2,my+5,s-mx-2,(my+top)/2,color.carpet,color.carpetL,1);
			draw_rectangle(mx,(my+top)/2+2,s-mx,top-3,color.snow,color.snowDD,1);
			draw_rectangle(mx+1,(my+top)/2+3,s-mx-1,top-4,color.snow,color.snowD,1);
			al_draw_line(mx+4,(my+top)/2+3,mx+3,(my+top)/2+9,color.carpet,2);

			// candle (top)
			mx-=5;
			my=50;
			draw_rectangle(mx*2-2,my,mx*2+2,s+2,color.sandL,color.sandD,1);
			al_draw_line(mx*2,my,mx*2,my-5,color.shadow,1);
			draw_ellipse(mx*2,my-3,2,3,color.carpetD,color.carpetL,1);
		}
	}
	else{
		if(aDir == LEFT || aDir == RIGHT){
			ALLEGRO_BITMAP* disp = al_get_target_bitmap();
			al_set_target_bitmap(buffer);
			al_clear_to_color(color.blank);

			// shadow
			drawGradient(mx,top,s,s-my,color.black,color.blank);
			drawGradient(mx*2-1,s-my,mx*2.7,s-my+3,color.shadowL,color.blank);

			// legs
			draw_rectangle(mx*2,top,mx*2.7,s-my,color.tree,color.treeDD,1);

			// tablecloth
			draw_rectangle(mx,my,s+2,top,color.clothLL,color.clothD,1);
			int y;
			for(int x=mx; x<s; x++){
				y = bot + sin(x/2.0)*2;
				al_draw_line(x,y-1,x+1,y-4,color.clothL,1);
				al_draw_line(x,y,x+1,y,color.clothD,1);
			}
			al_draw_filled_rectangle(mx,top,s,bot-3,color.clothL);
			al_draw_line(mx,top,mx,bot,color.clothD,1);

			// candle
			draw_ellipse(mx*2,(my+top)/2,4,3,color.iron,color.ironDD,1);
			draw_rectangle(mx*2-2,my/2+3,mx*2+2,(my+top)/2,color.sandL,color.sandD,1);
			al_draw_line(mx*2,my/2,mx*2,my/2+3,color.shadow,1);
			draw_ellipse(mx*2,my/2-2,2,3,color.carpetD,color.carpetL,1);

			al_set_target_bitmap(disp);
			if(aDir == LEFT) al_draw_bitmap(buffer,0,0,0);
			else al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
		}
		else{
			if(aDir == UP){
				// tablecloth
				draw_rectangle(my,mx,s-my,s+2,color.clothLL,color.clothD,1);

				// candle
				mx-=5;
				my+=13;
				top+=13;
				draw_ellipse(mx*2,(my+top)/2,4,3,color.iron,color.ironDD,1);
				draw_rectangle(mx*2-2,my/2+3,mx*2+2,(my+top)/2,color.sandL,color.sandD,1);
				al_draw_line(mx*2,my/2,mx*2,my/2+3,color.shadow,1);
				draw_ellipse(mx*2,my/2-2,2,3,color.carpetD,color.carpetL,1);
			}
			else{
				// shadow
				drawGradient(my,top,s-my,s-my,color.shadow,color.blank);
				drawGradient(my*2,s-my,s-my*2,s-my+3,color.shadowL,color.blank);

				// leg
				draw_rectangle(my*2,top,s-my*2,s-my,color.tree,color.treeDD,1);

				// tablecloth
				draw_rectangle(my,-2,s-my,mx,color.clothLL,color.clothD,1);
				int y;
				for(int x=my; x<s-my; x++){
					y = bot + sin(x/2.0)*2;
					al_draw_line(x,y-1,x+1,y-4,color.clothL,1);
					al_draw_line(x,y,x+1,y,color.clothD,1);
				}
				al_draw_filled_rectangle(my,mx,s-my,bot-3,color.clothL);
				al_draw_line(my,mx,my,bot,color.clothD,1);
				al_draw_line(s-my,mx,s-my,bot,color.clothD,1);

				// candle
				mx-=5;
				my-=15;
				top-=15;
				draw_ellipse(mx*2,(my+top)/2,4,3,color.iron,color.ironDD,1);
				draw_rectangle(mx*2-2,-2,mx*2+2,(my+top)/2,color.sandL,color.sandD,1);
			}
		}
	}

	noise(color.clothL,color.cloth,15);
	noise(color.clothLL,color.clothL,20);
	noise(color.tree,color.treeD,10);
}

void TileDrawer::drawTable(bool aChair){
	int rx = randInt(15,20);
	int ry = rx*2/3;
	int d = randInt(2,5);
	int h = randInt(12,14);

	if(aChair){
		rx/=2;
		ry/=2;
		d/=2;
		h/=2;
	}

	// shadow
	drawGradient(s/2-rx-1,s/2+d/2,s/2-rx+d,s/2+d+d/2,color.shadowL,color.blank);
	drawGradient(s/2+rx-d-1,s/2+d/2,s/2+rx,s/2+d+d/2,color.shadowL,color.blank);
	drawGradient(s/2-d/2-1,s/2+ry,s/2+d/2,s/2+ry+d,color.shadowL,color.blank);
	al_draw_filled_ellipse(s/2,s/2,rx-d,ry-d,color.shadowLL);
	al_draw_filled_ellipse(s/2,s/2,rx/3,ry/3,color.shadowLL);

	// legs
	draw_rectangle(s/2-rx,s/2-h,s/2-rx+d,s/2+d/2,color.tree,color.treeDD,1);
	draw_rectangle(s/2+rx-d,s/2-h,s/2+rx,s/2+d/2,color.tree,color.treeDD,1);
	draw_rectangle(s/2-d/2-1,s/2-h+ry,s/2+d/2,s/2+ry,color.tree,color.treeDD,1);

	// table top
  draw_ellipse(s/2,s/2-h,rx,ry,color.tree,color.treeDD,1);
	al_draw_filled_rectangle(s/2-rx,s/2-h-d,s/2+rx,s/2-h,color.tree);
	al_draw_line(s/2-rx,s/2-h-d,s/2-rx,s/2-h,color.treeDD,1);
	al_draw_line(s/2+rx,s/2-h-d,s/2+rx,s/2-h,color.treeDD,1);
	draw_ellipse(s/2,s/2-h-d,rx,ry,color.treeL,color.treeDD,1);

	noise(color.treeD,color.treeDD,20);
	noise(color.tree,color.treeD,20);
	noise(color.treeL,color.tree,20);
}

void TileDrawer::drawWardrobe(int aDir){
	int cx,cy,h,w,d,p,m;

	h = randInt(20,30);
	d = randInt(10,20);
	w = randInt(30,50);
	m = randInt(2,3);
	p = (h-4*m)/3;

	if(aDir == UP || aDir == DOWN){
		cy = randInt(d+h-d/2+1,d+h-d/2+m);
		cx = randInt(w/2+1,s-w/2-1);

		if(aDir == UP) cy = randInt(s-d/2,s-d/2-m);

		drawGradient(cx-w/2-1,cy+d/2,cx+w/2,cy+d/2+m*2,color.shadowL,color.blank);

		draw_rectangle(cx-w/2,cy-h+d/2,cx+w/2,cy+d/2,color.treeD,color.treeDD,1);
		draw_rectangle(cx-w/2,cy-h-d/2,cx+w/2,cy-h+d/2,color.treeL,color.treeDD,1);

		if(aDir == DOWN){
			draw_rectangle(cx-w/2+m,cy-h+d/2+m,cx+w/2-m,cy-h+d/2+m+p,color.tree,color.treeDD,1);
			draw_rectangle(cx-w/2+m,cy-h+d/2+m+p+m,cx+w/2-m,cy-h+d/2+m+p+m+p,color.tree,color.treeDD,1);
			draw_rectangle(cx-w/2+m,cy-h+d/2+m+p+m+p+m,cx+w/2-m,cy-h+d/2+m+p+m+p+m+p,color.tree,color.treeDD,1);

			draw_ellipse(cx,cy-h+d/2+m+p/2,m,m,color.treeD,color.treeDD,1);
			draw_ellipse(cx,cy-h+d/2+m+p+m+p/2,m,m,color.treeD,color.treeDD,1);
			draw_ellipse(cx,cy-h+d/2+m+p+m+p+m+p/2,m,m,color.treeD,color.treeDD,1);
		}
	}
	else{
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		w*=2/3.0;
		d*=3/2.0;
		cx = randInt(s-d/2-m,s-d/2-1);
		cy = randInt(w+h-w/2+1,s-w/2-1);

		drawGradient(cx-d/2-1,cy+w/2,cx+d/2,cy+w/2+m*2,color.shadowL,color.blank);

		draw_ellipse(cx-d/2,cy-h+m+p/2,m,m,color.treeD,color.treeDD,1);
		draw_ellipse(cx-d/2,cy-h+m+p+m+p/2,m,m,color.treeD,color.treeDD,1);
		draw_ellipse(cx-d/2,cy-h+m+p+m+p+m+p/2,m,m,color.treeD,color.treeDD,1);

		draw_rectangle(cx-d/2,cy-h+w/2,cx+d/2,cy+w/2,color.tree,color.treeDD,1);
		draw_rectangle(cx-d/2,cy-h-w/2,cx+d/2,cy-h+w/2,color.treeL,color.treeDD,1);

		al_set_target_bitmap(disp);
		if(aDir == RIGHT) al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
		else al_draw_bitmap(buffer,0,0,0);
	}

	noise(color.treeD,color.treeDD,20);
	noise(color.tree,color.treeD,20);
	noise(color.treeL,color.tree,20);
}

void TileDrawer::drawBarrel(){
	ALLEGRO_BITMAP* dispa = al_get_target_bitmap();
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	int cx,cy,rx,ry,h;

	rx = randInt(13,17);
	ry = rx*2/3;
	h = rx*2;
	cx = randInt(rx+1,s-rx-1);
	cy = randInt(ry*2+h-ry+1,s-ry-4);

	for(int i=1; i<4; i++) al_draw_filled_ellipse(cx,cy,rx+i,ry+i,color.shadowLL);

	for(int y=cy; y>=cy-h+2; y-=h/3){
		draw_ellipse(cx,y,rx,ry,color.tree,color.ironDD,1);
		draw_rectangle(cx-rx,y-h/4,cx+rx,y,color.tree,color.tree,1);
	}
	draw_ellipse(cx,cy-h,rx,ry,color.treeL,color.ironDD,1);

	al_draw_line(cx-rx,cy-h,cx-rx,cy,color.treeDD,1);
	al_draw_line(cx+rx+1,cy-h,cx+rx+1,cy,color.treeDD,1);

	draw_ellipse(cx,cy+ry-h/2,2,2,color.ironDD,color.treeDD,1);

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(x%5==0 && (eq(al_get_pixel(disp,x,y),color.tree))) al_put_pixel(x,y,color.treeD);
				if(y%4==0 && (eq(al_get_pixel(disp,x,y),color.treeL))) al_put_pixel(x,y,color.tree);
			}
		al_unlock_bitmap(disp);

	al_set_target_bitmap(dispa);
	al_draw_bitmap(buffer,0,0,0);

	noise(color.treeD,color.treeDD,15);
	noise(color.tree,color.treeD,15);
	noise(color.treeL,color.tree,15);
}

void TileDrawer::drawCrate(){
	int w = randInt(25,33);
	int d = w*2/3;
	float p = w/8.0;
	int x = randInt(1,s-w);
	int y = randInt(1,s-(w+d)-3);

	drawGradient(x+1,y+d+w,x+w,y+d+w+3,color.shadowL,color.blank);
	draw_rectangle(x,y,x+w,y+d,color.treeL,color.treeDD,1);
	draw_rectangle(x,y+d,x+w,y+d+w,color.tree,color.treeDD,1);

	float mx = x+p;
	for(int i=0; i<6; i++){
		draw_rectangle(mx,y+p*2/3,mx+p,y+d-p*2/3,color.tree,color.treeDD,1);
		draw_rectangle(mx,y+d+p,mx+p,y+d+w-p,color.treeD,color.treeDD,1);
		mx+=p;
	}

	Node plank[6] = {
		{x+p,y+d+p},{x+p+p*2/3,y+d+p},{x+p,y+d+p+p*2/3},
		{x+w-p-p*2/3,y+d+w-p},{x+w-p,y+d+w-p-p*2/3},{x+w-p,y+d+w-p}
	};
	for(int i=0; i<3; i++){plank[i].x++;plank[i].y++;}

	al_draw_filled_triangle(plank[0].x,plank[0].y,plank[1].x,plank[1].y,plank[2].x,plank[2].y,color.tree);
	al_draw_filled_triangle(plank[3].x,plank[3].y,plank[4].x,plank[4].y,plank[5].x,plank[5].y,color.tree);
	al_draw_filled_triangle(plank[1].x,plank[1].y,plank[2].x,plank[2].y,plank[3].x,plank[3].y,color.tree);
	al_draw_filled_triangle(plank[1].x,plank[1].y,plank[3].x,plank[3].y,plank[4].x,plank[4].y,color.tree);

	al_draw_line(plank[0].x,plank[0].y,plank[1].x,plank[1].y,color.treeDD,1);
	al_draw_line(plank[1].x,plank[1].y,plank[4].x,plank[4].y,color.treeDD,1);
	al_draw_line(plank[4].x,plank[4].y,plank[5].x,plank[5].y,color.treeDD,1);
	al_draw_line(plank[5].x,plank[5].y,plank[3].x,plank[3].y,color.treeDD,1);
	al_draw_line(plank[3].x,plank[3].y,plank[2].x,plank[2].y,color.treeDD,1);
	al_draw_line(plank[2].x,plank[2].y,plank[0].x,plank[0].y,color.treeDD,1);

	Node upperPlank[6] = {
		{x+p,y+d-p},{x+p+p*2/3,y+d-p},{x+p,y+d-p-p*2/3},
		{x+w-p-p*2/3,y+p},{x+w-p,y+p+p*2/3},{x+w-p,y+p}
	};
	for(int i=0; i<3; i++){upperPlank[i].x++;upperPlank[i].y++;}

	al_draw_filled_triangle(upperPlank[0].x,upperPlank[0].y,upperPlank[1].x,upperPlank[1].y,upperPlank[2].x,upperPlank[2].y,color.treeL);
	al_draw_filled_triangle(upperPlank[3].x,upperPlank[3].y,upperPlank[4].x,upperPlank[4].y,upperPlank[5].x,upperPlank[5].y,color.treeL);
	al_draw_filled_triangle(upperPlank[1].x,upperPlank[1].y,upperPlank[2].x,upperPlank[2].y,upperPlank[3].x,upperPlank[3].y,color.treeL);
	al_draw_filled_triangle(upperPlank[1].x,upperPlank[1].y,upperPlank[3].x,upperPlank[3].y,upperPlank[4].x,upperPlank[4].y,color.treeL);

	al_draw_line(upperPlank[0].x,upperPlank[0].y,upperPlank[1].x,upperPlank[1].y,color.treeDD,1);
	al_draw_line(upperPlank[1].x,upperPlank[1].y,upperPlank[4].x,upperPlank[4].y,color.treeDD,1);
	al_draw_line(upperPlank[4].x,upperPlank[4].y,upperPlank[5].x,upperPlank[5].y,color.treeDD,1);
	al_draw_line(upperPlank[5].x,upperPlank[5].y,upperPlank[3].x,upperPlank[3].y,color.treeDD,1);
	al_draw_line(upperPlank[3].x,upperPlank[3].y,upperPlank[2].x,upperPlank[2].y,color.treeDD,1);
	al_draw_line(upperPlank[2].x,upperPlank[2].y,upperPlank[0].x,upperPlank[0].y,color.treeDD,1);

	noise(color.treeD,color.treeDD,5);
	noise(color.tree,color.treeD,5);
	noise(color.treeL,color.tree,5);
}

void TileDrawer::drawChest(){
	int h = randInt(15,25);
	int d = h*2/3;
	int w = randInt(30,50);
	float p = w/10.0;
	int x = randInt(1,s-w);
	int y = randInt(1,s-(h+d)-3);

	drawGradient(x+1,y+d+h,x+w,y+d+h+3,color.shadowL,color.blank);
	draw_rectangle(x,y,x+w,y+d,color.treeL,color.treeDD,1);
	draw_rectangle(x,y+d,x+w,y+d+h,color.tree,color.treeDD,1);

	float mx = x+p;
	for(int i=0; i<8; i++){
		draw_rectangle(mx,y+p*2/3,mx+p,y+d-p*2/3,color.tree,color.treeDD,1);
		draw_rectangle(mx,y+d+p,mx+p,y+d+h-p,color.treeD,color.treeDD,1);
		mx+=p;
	}
	
	al_draw_line(x,y+d+1,x+w,y+d+1,color.ironDD,1);
	draw_rectangle(x+w/2-p/2,y+d,x+w/2+p/2,y+d+p*2,color.iron,color.ironDD,1);
	draw_rectangle(x+w/2-p/4,y+d+p/4,x+w/2+p/4,y+d+p*2-p/4,color.ironD,color.ironDD,1);

	noise(color.treeD,color.treeDD,15);
	noise(color.tree,color.treeD,15);
	noise(color.treeL,color.tree,15);
}

void TileDrawer::drawBucket(){
	ALLEGRO_BITMAP* dispa = al_get_target_bitmap();
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	int cx,cy,rx,ry,h;

	rx = randInt(10,12);
	ry = rx*2/3;
	h = rx*1.75;
	cx = randInt(rx+1,s-rx-1);
	cy = randInt(ry*2+h-ry+1,s-ry-4);

	for(int i=1; i<4; i++) al_draw_filled_ellipse(cx,cy,rx+i,ry+i,color.shadowLL);

	for(int y=cy; y>=cy-h+2; y-=h/3){
		draw_ellipse(cx,y,rx,ry,color.tree,color.ironDD,1);
		draw_rectangle(cx-rx,y-h/4,cx+rx,y,color.tree,color.tree,1);
	}
	draw_ellipse(cx,cy-h,rx,ry,color.waterD,color.treeDD,2);
	draw_ellipse(cx,cy-h,rx-4,ry-4,color.water,color.water,1);

	al_draw_line(cx-rx,cy-h,cx-rx,cy,color.treeDD,1);
	al_draw_line(cx+rx+1,cy-h,cx+rx+1,cy,color.treeDD,1);

	// noise
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(x%5==0 && (eq(al_get_pixel(disp,x,y),color.tree))) al_put_pixel(x,y,color.treeD);
				if(y%4==0 && (eq(al_get_pixel(disp,x,y),color.treeL))) al_put_pixel(x,y,color.tree);
			}
		al_unlock_bitmap(disp);

	al_set_target_bitmap(dispa);
	al_draw_bitmap(buffer,0,0,0);

	noise(color.treeD,color.treeDD,15);
	noise(color.tree,color.treeD,15);
	noise(color.treeL,color.tree,15);
}

void TileDrawer::drawAnvil(){
	int w = 30;
	int h = w/2;
	int p = 3;

	Node verts[] = {
		{0,-h},{w,-h},{w,0},{0,0},
		{-p,-h+p},{0,-h+p},{-p,0},{-w/2-p+5,-h+2*p+3},
		{0,h/3},{w-p,h/3},{w,h*2/3},{-p,h*2/3},
		{-p,-h+p*2}
	};

	int cx = 30;
	int cy = 30;

	int ex = cx+15;
	int ey = cy+15;

	for(int i=1; i<4; i++) al_draw_filled_ellipse(ex,ey,18+i,12+i,color.shadowLL);

	draw_ellipse(ex,ey,18,12,color.tree,color.treeDD,1);
	draw_rectangle(ex-18,cy,ex+18,ey,color.tree,color.blank,1);
	al_draw_line(ex-18,cy,ex-18,ey,color.treeDD,1);
	al_draw_line(ex+18,cy,ex+18,ey,color.treeDD,1);
	draw_ellipse(ex,cy,18,12,color.treeL,color.treeDD,1);

	for(int i=0; i<13; i++){ verts[i].x+=cx; verts[i].y+=cy-5; }

	draw_rectangle(verts[0].x,verts[0].y,verts[2].x,verts[2].y,color.iron,color.ironDD,1);
	draw_rectangle(verts[4].x,verts[4].y,verts[3].x,verts[3].y,color.ironD,color.ironDD,1);
	draw_triangle(verts[7].x,verts[7].y,verts[12].x,verts[12].y,verts[6].x,verts[6].y,color.iron,color.ironDD,1);

	Node quad1[] = {verts[6],verts[2],verts[8],verts[9]};
	draw_quad(quad1,color.ironD,color.ironDD,1);
	Node quad2[] = {verts[11],verts[8],verts[10],verts[9]};
	draw_quad(quad2,color.ironD,color.ironDD,1);

	draw_triangle(verts[6].x,verts[6].y,verts[8].x,verts[8].y,verts[11].x,verts[11].y,color.iron,color.ironDD,1);
	draw_triangle(verts[2].x,verts[2].y,verts[9].x,verts[9].y,verts[10].x,verts[10].y,color.iron,color.ironDD,1);

	drawGradient(verts[11].x,verts[11].y,verts[10].x,verts[10].y+3,color.shadowL,color.blank);

	noise(color.treeD,color.treeDD,5);
	noise(color.treeD,color.tree,5);
	noise(color.tree,color.treeD,5);
	noise(color.tree,color.treeDD,5);
	noise(color.treeL,color.tree,5);
	noise(color.treeL,color.treeD,5);

	noise(color.iron,color.ironD,15);
	noise(color.ironD,color.ironDD,15);
}

void TileDrawer::drawPot(){
	int mx = 5;
	int my = 10;
	int p = 5;

	// shadows
	drawGradient(mx+p-1,s-p*2,mx+p*2,s-p*2+3,color.shadowL,color.blank);
	drawGradient(s-mx-p+1,s-p*2,s-mx-p*2,s-p*2+3,color.shadowL,color.blank);
	for(int i=1; i<8; i+=2) al_draw_filled_ellipse(s/2,s*3/4,6+i,4+i,color.shadowLL);

	// poles
	draw_rectangle(mx+p,my+p,mx+p*2,s-p*2,color.tree,color.treeDD,1);
	draw_rectangle(s-mx-p,my+p,s-mx-p*2,s-p*2,color.tree,color.treeDD,1);

	// ring
	int rx = (s-2*(mx+p*3))/2;
  draw_rectangle(mx,my+p/2,s-mx,my+p,color.tree,color.treeDD,1);
	al_draw_ellipse(s/2,s/3,rx,s/3-my,color.ironDD,2);
	draw_rectangle(s/2,my+p/2,s-mx,my+p,color.tree,color.treeDD,1);

	// triangles
	draw_triangle(mx+p/2,my,mx+p*2+p/2,my,mx+p+p/2,my+p+p/2,color.treeL,color.treeDD,1);
	draw_triangle(s-mx-p/2,my,s-mx-p*2-p/2,my,s-mx-p-p/2,my+p+p/2,color.treeL,color.treeDD,1);

	// pot
	draw_ellipse(s/2,s/2+p/2,rx+p/2,rx,color.ironDD,color.ironDD,1);
	draw_ellipse(s/2,s/2,rx,rx-p/2,color.ironD,color.ironD,1);
	draw_ellipse(s/2,s/2,rx,rx-p-p/2,color.iron,color.iron,1);

	draw_ellipse(s/2,s/2-p,rx,rx/2,color.iron,color.ironDD,1);
	draw_ellipse(s/2,s/2-p,rx-p/2,rx/2-p/2,color.leafD,color.ironDD,1);

	noise(color.treeD,color.treeDD,10);
	noise(color.tree,color.treeD,10);
	noise(color.treeL,color.tree,10);

	noise(color.ironD,color.iron,10);
	noise(color.iron,color.ironD,10);

	noise(color.leafD,color.leaf,10);
	noise(color.leafD,color.leafL,10);
	noise(color.leafD,color.leafDD,10);
}

void TileDrawer::drawBench(bool aVert){
	int mx = 5;
	int my = 20;
	int d = 10;
	int h = 4;

	if(aVert){
		my+=3;
		drawGradient(my,s-mx-h*2,s-my,s-mx+3,color.shadow,color.blank);

		draw_rectangle(my,mx,s-my,s-mx-h*2,color.treeL,color.treeDD,1);
		draw_rectangle(my,s-mx-h*2,s-my,s-mx-h,color.tree,color.treeDD,1);
		draw_rectangle(my,s-mx-h,my+h,s-mx,color.treeD,color.treeDD,1);
		draw_rectangle(s-my-h,s-mx-h,s-my,s-mx,color.treeD,color.treeDD,1);
	}
	else{
		drawGradient(mx,my+d,s-mx,my+d+2*h+3,color.shadow,color.blank);

		draw_rectangle(mx,my+d+h,mx+h,my+d+h*2,color.treeD,color.treeDD,1);
		draw_rectangle(s-mx,my+d+h,s-mx-h,my+d+h*2,color.treeD,color.treeDD,1);
		draw_rectangle(mx,my,s-mx,my+d,color.treeL,color.treeDD,1);
		draw_rectangle(mx,my+d,s-mx,my+d+h,color.tree,color.treeDD,1);
	}

	noise(color.treeD,color.treeDD,5);
	noise(color.tree,color.treeD,5);
	noise(color.treeL,color.tree,5);
}

void TileDrawer::drawCandle(int aX, int aY){
	int w = 4;
	int h = 8;
	int t = 6;
	int r = w;

	draw_ellipse(aX,aY,r,r*2/3,color.iron,color.ironDD,1);
	draw_rectangle(aX-w/2,aY-h,aX+w/2,aY,color.sandL,color.sandD,1);
	al_draw_line(aX,aY-h-t,aX,aY-h,color.shadow,1);
	draw_ellipse(aX,aY-h-t,w/2,w,color.carpet,color.carpetL,1);
}

void TileDrawer::drawCandlestick(){
	int w = 5;
	int mx = 15;
	int my = 5;
	int c = 10;

	float cy = s-my-10;
	float rx = 10;

	al_draw_filled_ellipse(s/2,cy,rx+3,rx*2/3+3,color.shadowLL);

	draw_ellipse(s/2,cy,rx,rx*2/3,color.banana,color.bananaDD,1);
	draw_ellipse(s/2,cy,rx/2,rx/3,color.sandD,color.sandD,1);

	draw_rectangle(s/2-w/2,my+c,s/2+w/2,cy,color.banana,color.bananaDD,1);
	draw_rectangle(mx,my+c+w,s-mx,my+c+w*2,color.banana,color.bananaDD,1);

	draw_rectangle(mx,my+c,mx+w,my+c+w,color.banana,color.bananaDD,1);
	draw_rectangle(s-mx-w,my+c,s-mx,my+c+w,color.banana,color.bananaDD,1);

	draw_ellipse(s/2,my+c+w+w/2,5,5,color.banana,color.bananaDD,1);

	drawCandle(mx+w/2,my+c);
	drawCandle(s/2,my+c-1);
	drawCandle(s-mx-w/2,my+c);
}

void TileDrawer::drawPlant(){
	int ts = s;

	for(int i=1; i<4; i++) al_draw_filled_ellipse(s/2,s/2+13,12+i,8+i,color.shadowLL);

	// pot
	int p = 5;
	int rx = 10;
	int my = 7;
	draw_ellipse(s/2,my+s/2+p/2,rx+p/2,rx,color.stoneD,color.houseB,1);
	draw_ellipse(s/2,my+s/2,rx,rx-p/2,color.stone,color.stone,1);
	draw_ellipse(s/2,my+s/2,rx,rx-p-p/2,color.stoneL,color.stoneL,1);

	draw_ellipse(s/2,my+s/2-p,rx,rx/2,color.stoneL,color.stoneD,1);
	draw_ellipse(s/2,my+s/2-p,rx-p/2,rx/2-p/2,color.treeD,color.houseB,1);

	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);
	s = s/2+10;
	int delay = ts/2 - s/2;
	drawTree(SCLEROPHYLL);
	s = ts;
	al_set_target_bitmap(disp);
	al_draw_bitmap(buffer,delay,0,0);

	noise(color.stone,color.stoneD,10);
	noise(color.stoneL,color.stone,10);
}

void TileDrawer::drawSign(){
	int m = 8;

	al_draw_filled_rectangle(m,s-m*1.5,s-m,s-m+2,color.shadowLLL);
	drawGradient(2*m-1,s-m,3*m,s-m+3,color.shadowL,color.blank);
	drawGradient(s-3*m-1,s-m,s-2*m,s-m+3,color.shadowL,color.blank);

	draw_rectangle(m,m,s-m,m*2,color.treeL,color.treeDD,1);
	draw_rectangle(m,2*m,s-m,s-m*2,color.tree,color.treeDD,1);
	draw_rectangle(2*m,s-m*2,3*m,s-m,color.treeD,color.treeDD,1);
	draw_rectangle(s-3*m,s-m*2,s-2*m,s-m,color.treeD,color.treeDD,1);

	noise(color.treeD,color.treeDD,5);
	noise(color.tree,color.treeD,5);
	noise(color.treeL,color.tree,5);
}

void TileDrawer::drawWeaponIcon(){
	int m = 13;
	int p = 8;

	draw_rectangle(m,s/2-p/3,m+p,s/2+p/3,color.ironD,color.ironDD,1);
	draw_rectangle(m+p*1.5,s/2-p/2,s-m-p,s/2+p/2,color.iron,color.ironDD,1);
	draw_rectangle(m+p,s/2-p-p/3,m+p*1.5,s/2+p+p/3,color.treeL,color.treeDD,1);

	draw_triangle(s-m-p,s/2-p/2-1,s-m-p,s/2+p/2,s-m,s/2,color.iron,color.ironDD,1);
	al_draw_line(s-m-p,s/2-p/2+1,s-m-p,s/2+p/2-1,color.iron,1);
	al_draw_line(m+p*1.5,s/2,s-m-p,s/2,color.ironD,1);

	noise(color.iron,color.ironD,15);
	noise(color.ironD,color.ironDD,15);
	noise(color.treeL,color.tree,5);
}

void TileDrawer::drawArmorIcon(){
	int mx = 22;
	int my = 20;
	int p = 4;
	int bot = s*2/3-p*1.5;

	draw_rectangle(mx,my,s-mx,bot,color.ironD,color.ironDD,1);
	draw_triangle(mx,bot,s-mx-1,bot,s/2,bot+p*2,color.ironD,color.ironDD,1);
	al_draw_line(mx+1,bot,s-mx-1,bot,color.ironD,1);

	draw_rectangle(mx+p,my+p,s-mx-p,bot,color.iron,color.ironDD,1);
	draw_triangle(mx+p,bot,s-mx-1-p,bot,s/2,bot+p/2,color.iron,color.ironDD,1);
	al_draw_line(mx+1+p,bot,s-mx-1-p,bot,color.iron,1);

	noise(color.iron,color.ironD,15);
	noise(color.ironD,color.ironDD,15);
	noise(color.treeL,color.tree,5);
}

void TileDrawer::drawHerbsIcon(){
	int r = 7;
	int p = 3;
	int h = 5;
	int cy = 37;

	draw_ellipse(s/2,cy,r,r,color.leaf,color.shadow,1);
	al_draw_filled_rectangle(s/2-p,cy-r-h,s/2+p,cy,color.leaf);
	al_draw_line(s/2-p,cy-r-h,s/2-p,cy-r,color.shadow,1);
	al_draw_line(s/2+p,cy-r-h,s/2+p,cy-r,color.shadow,1);
	al_draw_filled_rectangle(s/2-p,cy-r-h,s/2+p-1,cy-r-h/2,color.waterL);

	draw_rectangle(s/2-p*1.5,cy-r-h-p,s/2+p*1.5-1,cy-r-h,color.water,color.shadow,1);
	draw_rectangle(s/2-p,cy-r-h-p*2,s/2+p,cy-r-h-p,color.woodL,color.woodDD,1);

	noise(color.leaf,color.leafL,10);
}

void TileDrawer::drawInnIcon(){
	int rx = 12;
	int ry = 10;
	int cx = s/2;
	int cy = 31;

	for(float i=0; i<ALLEGRO_PI*2.0; i+=0.5)
		al_draw_line(cx, cy, cx+rx*sin(i), cy+ry*cos(i), color.bananaDD, 2);
	draw_ellipse(cx, cy, rx/2, ry/2,color.banana,color.bananaDD,1);
}

void TileDrawer::drawSignWeapon(){
	drawSign();
	drawWeaponIcon();
}

void TileDrawer::drawSignArmor(){
	drawSign();
	drawArmorIcon();
}

void TileDrawer::drawSignHerbs(){
	drawSign();
	drawHerbsIcon();
}

void TileDrawer::drawSignInn(){
	drawSign();
	drawInnIcon();
}

void TileDrawer::drawGrave(){
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	int w = randInt(25,45);
	int h = randInt(20,35);
	int d = randInt(3,6);
	int r = randInt(w/4,w/2);
	int x = randInt(1,s-w);
	int y = randInt(d+1,s-h-h/3);

	draw_rounded_rectangle(x,y-d,x+w,y+h*2,r,r,color.pavementL,color.pavementDD,1);
	draw_rounded_rectangle(x,y,x+w,y+h*2,r,r,color.pavement,color.pavementDD,1);
	draw_rectangle(x,y+h,x+w,y+h*2,color.mpink,color.mpink,1);

	noise(color.mpink,color.blank,1);

	drawGradient(x-1,y+h,x+w,y+h+h/3,color.shadowL,color.blank);

	for(int i=y+r; i<y+h-3; i+=5)
		al_draw_line(x+5,i,x+w-5,i,color.pavementD,2);

	for(int i=x; i<x+w+1; i++){
		int ty = randInt(y+h,y+h+3);
		al_draw_line(i,y+h-1,i,ty,color.pavement,1);
	}

	if(w>35) al_draw_circle(x+w/2,y+r/2,3,color.pavementD,1);

	noise(color.pavementD,color.pavementDD,5);
	noise(color.pavement,color.pavementD,5);
	noise(color.pavementL,color.pavement,5);
	noise(color.pavementDD,color.ironD,1);

	al_set_target_bitmap(disp);
	al_draw_bitmap(buffer,0,0,0);
}

void TileDrawer::drawFence(bool aConnections[4]){
	int cx = s/2;
	int cy = s*2/3;
	int h = 20;
	int r = 5;
	int p = 4;

	if(aConnections[0]){
		al_draw_filled_rectangle(-2,cy-p/2,cx,cy+p/2,color.shadowLL);
		draw_rectangle(-2,cy-h+p,cx,cy-h+2*p,color.tree,color.treeDD,1);
		draw_rectangle(-2,cy-2*p,cx,cy-p,color.tree,color.treeDD,1);
	}
	if(aConnections[1]){
		al_draw_filled_rectangle(cx,cy-p/2,s+2,cy+p/2,color.shadowLL);
		draw_rectangle(cx,cy-h+p,s+2,cy-h+2*p,color.tree,color.treeDD,1);
		draw_rectangle(cx,cy-2*p,s+2,cy-p,color.tree,color.treeDD,1);
	}
	if(aConnections[2]){
		draw_rectangle(cx-p/2,-2,cx+p/2+1,cx-2,color.treeL,color.treeDD,1);
	}

	al_draw_filled_ellipse(cx,cy,r+1,r*2/3+1,color.shadowL);
	draw_ellipse(cx,cy,r,r*2/3,color.tree,color.treeDD,1);
	al_draw_filled_rectangle(cx-r,cy-h,cx+r,cy,color.tree);
	al_draw_line(cx-r+1,cy-h,cx-r,cy,color.treeDD,1);
	al_draw_line(cx+r,cy-h,cx+r,cy,color.treeDD,1);
	draw_ellipse(cx,cy-h,r,r*2/3,color.treeL,color.treeDD,1);

	if(aConnections[3]){
		draw_rectangle(cx-p/2,cy-h+r,cx+p/2+1,s+2,color.treeL,color.treeDD,1);
	}

	noise(color.treeD,color.treeDD,10);
	noise(color.tree,color.treeD,10);
	noise(color.treeL,color.tree,10);
}

void TileDrawer::drawWell(){
	int r = 20;
	int mr = r*2/3;
	int h = 20;
	int rings = 5;
	int d = h/rings;

	int cx = s/2;
	int cy = s*3/4;

	// shadow
	for(int i=1; i<4; i++) al_draw_filled_ellipse(cx,cy,r+i,r*2/3+i,color.shadowLL);

	// well rings
	for(int i=0; i<rings; i++){
		ALLEGRO_COLOR c = color.mpink;
		if(i%2) c = color.banana;
		draw_ellipse(cx,cy-d*i,r,r*2/3,c,color.black,1);
		draw_rectangle(cx-r+1,cy-r/3-d*i,cx+r,cy-d*i,c,color.black,1);
		al_draw_line(cx-r+2,cy-d*i,cx+r-1,cy-d*i,c,1);
	}

	// vertical bricks edges
	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_lock_bitmap(disp,al_get_bitmap_format(disp),ALLEGRO_LOCK_READWRITE);
		for(int x=0; x<s; x++)
			for(int y=0; y<s; y++){
				if(x%10==5 && (eq(al_get_pixel(disp,x,y),color.mpink))) al_put_pixel(x,y,color.black);
				if(x%10==0 && (eq(al_get_pixel(disp,x,y),color.banana))) al_put_pixel(x,y,color.black);
			}
		al_unlock_bitmap(disp);

	// colorize
	noise(color.mpink,color.pavementD,1);
	noise(color.banana,color.pavementD,1);
	noise(color.black,color.pavementDD,1);

	// top
	draw_ellipse(cx,cy-h,r,r*2/3,color.pavement,color.pavementDD,1);
	for(float i=0; i<ALLEGRO_PI*2.0; i+=0.5)
		al_draw_line(cx, cy-h, cx+r*sin(i), cy-h+r*2/3*cos(i), color.pavementDD, 1);
	draw_ellipse(cx,cy-h,mr,mr*2/3,color.pavementDD,color.pavementDD,1);

	// noise
	noise(color.pavementDD,color.ironD,1);
	noise(color.pavementD,color.pavementDD,10);
	noise(color.pavement,color.pavementD,5);

}

void TileDrawer::drawMarketStand(){
	int m = 15;
	float p = 5;
	int h = 10;
	int mx = randInt(7,13);

	// shadow
	drawGradient(mx,s-m,s-mx,s-m+3,color.shadow,color.blank);

	// box
	draw_rectangle(mx,m,s-mx,s-m-h,color.treeD,color.treeDD,1);
	draw_rectangle(mx,s-m-h,s-mx,s-m,color.tree,color.treeDD,1);

	draw_rectangle(mx,m,s-mx,m+p,color.treeL,color.treeDD,1);

	// fruits
	ALLEGRO_COLOR fruit[] = {color.banana,color.carpet,color.wood,color.leaf};
	ALLEGRO_COLOR fruitB[] = {color.bananaDD,color.carpetD,color.woodDD,color.leafDD};
	int colIndex = rand()%4;
	ALLEGRO_COLOR col = fruit[colIndex];
	ALLEGRO_COLOR colB = fruitB[colIndex];
	int pro = randInt(50,150);
	float prop = pro/100.0;
	for(int i=0; i<40; i++){
		int rx = randInt(p,1.5*p);
		int ry = rx*prop;
		int x = randInt(rx+mx,s-rx-mx);
		int y = randInt(m+ry+p/2,s-m-h-ry-1);

		draw_ellipse(x,y,rx,ry,col,colB,1);
	}

	draw_rectangle(mx,s-m-h-p,s-mx,s-m-h,color.treeL,color.treeDD,1);
	draw_rectangle(mx,m,p+mx,s-m-h,color.treeL,color.treeDD,1);
	draw_rectangle(s-p-mx,m,s-mx,s-m-h,color.treeL,color.treeDD,1);

	al_draw_line(mx,s-m-h/2,s-mx,s-m-h/2,color.treeDD,1);

	noise(color.treeD,color.treeDD,5);
	noise(color.tree,color.treeD,5);
	noise(color.treeL,color.tree,5);

	noise(col,colB,5);
}

void TileDrawer::drawThrone(int aDir){
	int w = 35;
	int h = 50;
	int p = 5;
	int x = s/2-w/2;
	int y = s/2-h/2+5;

	if(aDir == UP || aDir == DOWN){
		drawGradient(x-1,y+h,x+w,y+h+3,color.shadowL,color.blank);

		draw_rectangle(x,y,x+w,y+h,color.tree,color.treeDD,1);

		draw_rectangle(x,y-p*1.75,x+p,y-p,color.treeL,color.treeDD,1);
		draw_rectangle(x,y-p,x+p,y,color.tree,color.treeDD,1);
		draw_rectangle(x+p,y-p*0.75,x+w-p,y,color.treeL,color.treeDD,1);
		draw_rectangle(x+w-p,y-p*1.75,x+w,y-p,color.treeL,color.treeDD,1);

		draw_rectangle(x+w-p,y-p,x+w,y,color.tree,color.treeDD,1);

		if(aDir == DOWN){
			draw_rectangle(x+p,y+p,x+w-p,y+h-p,color.carpetL,color.carpetD,1);

			draw_rectangle(x+p*1.5,y+h/2,x+w-p*1.5,y+h*2/3+3,color.carpetL,color.carpetD,1);
			draw_rectangle(x+p*1.5,y+h*2/3+3,x+w-p*1.5,y+h,color.carpet,color.carpetD,1);

			draw_rectangle(x,y+h/2-3,x+p*1.5,y+h*2/3,color.treeL,color.treeDD,1);
			draw_rectangle(x,y+h*2/3,x+p*1.5,y+h,color.tree,color.treeDD,1);
			draw_rectangle(x+w-p*1.5,y+h/2-3,x+w,y+h*2/3,color.treeL,color.treeDD,1);
			draw_rectangle(x+w-p*1.5,y+h*2/3,x+w,y+h,color.tree,color.treeDD,1);
		}
	}
	else{
		ALLEGRO_BITMAP* disp = al_get_target_bitmap();
		al_set_target_bitmap(buffer);
		al_clear_to_color(color.blank);

		y-=10;

		drawGradient(x-1,y+h,x+w,y+h+3,color.shadowL,color.blank);

		draw_rectangle(x,y-p*1.75,x+p,y-p,color.treeL,color.treeDD,1);
		draw_rectangle(x,y-p,x+p,y,color.tree,color.treeDD,1);
		
		draw_rectangle(x,y,x+p,y+p*2,color.treeL,color.treeDD,1);

		draw_rectangle(x,y+p*2,x+p,y+p*3,color.treeL,color.treeDD,1);
		draw_rectangle(x,y+p*3,x+p,y+h,color.tree,color.treeDD,1);

		y+=10;
		draw_rectangle(x+p,y+p/2,x+w,y+p*1.5-2,color.treeL,color.treeDD,1);
		draw_rectangle(x+p,y+p*1.5-2,x+w,y+p*2.5,color.tree,color.treeDD,1);
		draw_rectangle(x+p,y+p*2.5,x+w,y+p*3.5,color.carpetL,color.treeDD,1);
		draw_rectangle(x+p,y+p*3.5,x+w,y+p*4.5,color.treeL,color.treeDD,1);
		draw_rectangle(x+p,y+p*4.5,x+w,y+h-10,color.tree,color.treeDD,1);

		al_set_target_bitmap(disp);
		if(aDir == LEFT) al_draw_bitmap(buffer,0,0,ALLEGRO_FLIP_HORIZONTAL);
		else al_draw_bitmap(buffer,0,0,0);
	}

	noise(color.carpet,color.carpetD,5);
	noise(color.carpetL,color.carpet,5);
}

void TileDrawer::drawArmor(){
	int w = 30;
	int h = 10;
	int d = w*2/3;
	int x = s/2-w/2;
	int y = s*3/4-h/2;
	int p = 6;


	drawGradient(x-1,y+h,x+w,y+h+3,color.shadowL,color.blank);
	draw_rectangle(x,y,x+w,y+h, color.pavement, color.mpink, 1);
	draw_rectangle(x,y-d,x+w,y, color.pavementL, color.mpink,1);
	al_draw_filled_ellipse(x+w/2,y-d/2,w/3,w/5,color.shadowLL);
	draw_rectangle(x+w/2-p/2,y-d/2-h*3,x+w/2+p/2,y-d/2,color.iron,color.mpink,1);

	al_draw_line(x+3,y+h/2,x+w-3,y+h/2,color.pavementD,2);

	ALLEGRO_BITMAP* disp = al_get_target_bitmap();
	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	drawArmorIcon();

	al_set_target_bitmap(disp);
	al_draw_bitmap(buffer,0,-15,0);

	al_set_target_bitmap(buffer);
	al_clear_to_color(color.blank);

	drawWeaponIcon();

	al_set_target_bitmap(disp);
	al_draw_bitmap(buffer,0,-13,0);

	noise(color.tree,color.pavement,1);
	noise(color.treeL,color.pavement,1);
	noise(color.iron,color.pavement,1);
	noise(color.ironD,color.pavementD,1);
	noise(color.ironDD,color.ironD,1);
	noise(color.mpink,color.ironD,1);
	noise(color.treeDD,color.ironD,1);

	noise(color.pavementD,color.pavementDD,10);
	noise(color.pavement,color.pavementD,10);
	noise(color.pavementL,color.pavement,10);
}

//*********************************************
//* MAZE MAP SPECIFIC
//*********************************************

void TileDrawer::drawTorch()
{
	float d = s/8;
	draw_triangle(s/2,s*3/4+d,s/2.5,s/2+d,s-s/2.5,s/2+d,color.wood,color.woodDD,1);

	al_draw_line(s/2-d,45,s/2+d,45,color.ironDD,2);
}

void TileDrawer::drawLadder()
{
	float hw = s/5;
	float bar = s/5;
	float m = 4;
	
	al_draw_filled_rectangle(s/2-hw-m/2,s-m/2,s/2+hw+m/2,s,color.shadowL);

	for(int y = bar/2; y<s; y+=bar)
	{
		draw_rectangle(s/2-hw+m,y,s/2+hw-m,y+m,color.iron,color.ironDD,1);
	}
	draw_rectangle(s/2-hw,3,s/2-hw+m,s-2,color.iron,color.ironDD,1);
	draw_rectangle(s/2+hw-m,3,s/2+hw,s-2,color.iron,color.ironDD,1);

	draw_ellipse(s/2-hw+m/2,m/2,m/2,m/2,color.ironDD,color.ironDD,1);
	draw_ellipse(s/2+hw-m/2,m/2,m/2,m/2,color.ironDD,color.ironDD,1);
}